Recent

Author Topic: BINGO application  (Read 5228 times)

seghele0

  • Full Member
  • ***
  • Posts: 207
BINGO application
« on: August 14, 2024, 10:50:50 am »
I've been organizing Bingo every month  in two "retirement homes" for some time now.
This is done with wooden blocks with 75 different numbers that are removed 1 by 1 from a linen bag.
If I could use a more practical system with my laptop, this could only mean real progress.
The code I obtained on Google and am sending, is far too complex for my level of programming.
The two procedures with problems are: "GenerateBingoCard" and "DrawNumber".
Hopefully some kind soul can help me with the correct code.
 :-[

Zvoni

  • Hero Member
  • *****
  • Posts: 2640
Re: BINGO application
« Reply #1 on: August 14, 2024, 11:28:47 am »
Going with the classic:
So you need a 5x5 (25 numbers) Bingo-Card in whatever random order, plus as gamemaster the drawing of random numbers until someone screams BINGO!

Keyword for both: Durstenfeld / Satollo
for the Card: Draw 25 Numbers using Durstenfeld, and assign them to the Grid
As GM: Use Durstenfeld click by click

Note: in both cases you don't need to check if a Number has already been drawn, because it's impossible to draw a number twice

If i'm bored enough, i might whip up a proof of concept later
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Zvoni

  • Hero Member
  • *****
  • Posts: 2640
Re: BINGO application
« Reply #2 on: August 14, 2024, 12:57:14 pm »
Proof of concept.
No Sanity checks whatsoever (not my job)

EDIT: To anyone who downloaded my PoC:
Feel free to review, improve and/or point out mistakes or nonsense.
I can only learn from your input.
« Last Edit: August 14, 2024, 01:59:44 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Full Member
  • ***
  • Posts: 207
Re: BINGO application
« Reply #3 on: August 14, 2024, 02:12:58 pm »
In attachment I leave a possible example of the screen.
Each time the "Draw Number" button is pressed, another number that is not yet indicated on the screen (in the center) with the 75 numbers is generated by showing the new selected number in a certain (same) color.
You can clearly read on the screen which numbers have not yet been dialed and which have already been called.
The panel at the top right of the screen always shows the latest new number.

There was not enough space to display all the selected numbers and when you press the "Draw numbers" button 76 times, an error appears.
So the Tedit (Edit Number) is no longer necessary.

In any case, I would like to thank you for your commitment to the elderly
 ;)


Zvoni

  • Hero Member
  • *****
  • Posts: 2640
Re: BINGO application
« Reply #4 on: August 14, 2024, 02:25:30 pm »
There was not enough space to display all the selected numbers and when you press the "Draw numbers" button 76 times, an error appears.
What i wrote: No Sanity checks whatsoever. Your job, not mine
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Full Member
  • ***
  • Posts: 207
Re: BINGO application
« Reply #5 on: August 14, 2024, 03:24:21 pm »
In any case, thank you for your efforts.
 ;)
Perhaps there is another professional programmer who will take on a challenge.
 ::)


Thaddy

  • Hero Member
  • *****
  • Posts: 15555
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #6 on: August 14, 2024, 03:46:55 pm »
This is a very few liner:
Code: Pascal  [Select][+][-]
  1. program bingo;
  2. {$ifdef fpc}{$mode delphi}{$endif}
  3. uses math;
  4. var
  5.   a:Array of cardinal;
  6.   i,j,t:cardinal;
  7. begin
  8.   // initialize
  9.   setlength(a,75);
  10.   for i := 0 to high(a) do a[i] := i;
  11.   randomize;
  12.   i := high(a);
  13.    repeat
  14.      dec(i);
  15.      j :=randomrange(0,i);
  16.      t:=a[i];a[i]:=a[j];a[j]:=t;
  17.      write(a[i]:3);
  18.    // supposes a bingo card of 5x5, adapt here:
  19.      if (i+1) mod 5 = 0 then writeln; // dimensions of the card
  20.    until i=49;  //   << 25 numbers from 75
  21.   readln;
  22. end.
This uses the sattolo cycle algorithm.
It generates 25 unique numbers from a set of 75.
« Last Edit: August 14, 2024, 03:59:37 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Zvoni

  • Hero Member
  • *****
  • Posts: 2640
Re: BINGO application
« Reply #7 on: August 14, 2024, 03:52:49 pm »
This is a very few liner:
Code: Pascal  [Select][+][-]
  1. program bingo;
  2. {$ifdef fpc}{$mode delphi}{$endif}
  3. uses math;
  4. var
  5.   a:Array of cardinal;
  6.   i,j,t:cardinal;
  7. begin
  8.   // initialize
  9.   setlength(a,75);
  10.   for i := 0 to high(a) do a[i] := i;
  11.   randomize;
  12.    // supposes a bingo card of 5x5, adapt here.
  13.   i := high(a);
  14.    repeat
  15.      dec(i);
  16.      j :=randomrange(0,i);
  17.      t:=a[i];a[i]:=a[j];a[j]:=t;
  18.      write(a[i]:3);
  19.    until i=49;    
  20.   readln;
  21. end.
This uses the sattolo cycle algorithm.
It generates 25 unique numbers from a set of 75.
Thaddy, close.....
You need a positive offset of +1 for the values. (Line 10)
Your code uses 0..74 as the values for Bingo, which would be "wrong".
It needs 1..75

And Line 15+16 just doesn't make sense to me...
In line 13 you set i to High(a), which is 74
In Line 15 you decrease i, which makes it 73
in Line 16 you want a randomrange between 0 and 73
which would mean, 74 cannot be picked.

I would have expected Line 15 between Line 18 and 19
« Last Edit: August 14, 2024, 03:56:41 pm by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

seghele0

  • Full Member
  • ***
  • Posts: 207
Re: BINGO application
« Reply #8 on: August 14, 2024, 03:59:39 pm »
Thanks, but as I said, I don't have the skills to program a complex program.
Hopefully you can pick it up and make adjustments in the attached program.
 :-[


Thaddy

  • Hero Member
  • *****
  • Posts: 15555
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #9 on: August 14, 2024, 04:00:25 pm »
@Zvoni
Oh, well, that is even easy for OP  :)
My code is as easy as it gets.
I am not even tempted to adapt it.

(No, I don't play Bingo )
 :D

Oh, well 2:
Code: Pascal  [Select][+][-]
  1. program bingo;
  2. {$ifdef fpc}{$mode delphi}{$endif}
  3. uses math;
  4. var
  5.   a:Array of cardinal;
  6.   i,j,t:cardinal;
  7. begin
  8.   // initialize
  9.   setlength(a,75);
  10.   for i := 0 to high(a) do a[i] := i;
  11.   randomize;
  12.    // supposes a bingo card of 5x5, adapt here.
  13.   i := high(a)+1;
  14.    repeat
  15.      dec(i);
  16.      j :=randomrange(1,i);
  17.      t:=a[i];a[i]:=a[j];a[j]:=t;
  18.      write(a[i]+1:3);
  19.      if i mod 5 = 0 then writeln;
  20.   until i=50;    
  21.   readln;
  22.   write(#7)// bell;
  23. end.

Bingo!  :P ::)
« Last Edit: August 14, 2024, 05:41:23 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

seghele0

  • Full Member
  • ***
  • Posts: 207
Re: BINGO application
« Reply #10 on: August 14, 2024, 05:30:12 pm »
Oops.....the procedure is not a complete program.
 %)

Thaddy

  • Hero Member
  • *****
  • Posts: 15555
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #11 on: August 14, 2024, 05:44:01 pm »
My program? That is complete and the second version does not allow for 0.
You can make that into a function, though. And the algorithm is shorter.
tip: if there is a readln in the loop, it will pause and displays the next value when a key is pressed....
It bingos all the way.... :P
My code is documented in:
https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
more specific the sattolo mention.
« Last Edit: August 14, 2024, 06:05:41 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

dbannon

  • Hero Member
  • *****
  • Posts: 3024
    • tomboy-ng, a rewrite of the classic Tomboy
Re: BINGO application
« Reply #12 on: August 15, 2024, 03:20:05 am »
...
The code I obtained on Google and am sending, is far too complex for my level of programming.

seghele0, this code "obtained from Google", has no copyright, author etc information, it looks as if it was AI generated. That means, parts, maybe even the whole, could be copyright and the AI has simply stripped out the 'inconvenient' ownership details.

Just a "heads up" ....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

seghele0

  • Full Member
  • ***
  • Posts: 207
Re: BINGO application
« Reply #13 on: August 15, 2024, 10:34:45 am »
Sorry, I don't follow your programming intelligence.
Thanks anyway
 ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 15555
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #14 on: August 15, 2024, 12:34:11 pm »
Who has better art work? (this one generated by AI)
Making progress to make a free bingo app that can also print cards, with audio and game progress...
(Pensionado with nothing better to do..)

Maybe I should be playing Bingo?  O:-)

Algorithm based on my second example.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018