Recent

Author Topic: BINGO application  (Read 4634 times)

dbannon

  • Hero Member
  • *****
  • Posts: 2999
    • tomboy-ng, a rewrite of the classic Tomboy
Re: BINGO application
« Reply #15 on: August 15, 2024, 02:53:35 pm »
....
Maybe I should be playing Bingo?  O:-)

No, make the software. At least the code will not be AI !  And it will probably work ....

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: 201
Re: BINGO application
« Reply #16 on: August 15, 2024, 05:12:43 pm »
Dear 'top' programmers, I'm making one last attempt for your support.
The code below comes from A.I., but it doesn't work.
Among other things: "InitiakizeGrid" and "Add(Pointer(Num))" give error.
I understand that you don't like to pass on "free" code.
But it isn't about a complete program.
I hope for a positive solution!
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5.   Classes, SysUtils, Forms, Controls,
  6.   Graphics, Dialogs, StdCtrls, Grids;
  7. type
  8.   { TMAINFORM }
  9.     TMainForm = class(TForm)
  10.     DRAWbutton: TButton;
  11.     BingoGrid: TStringGrid;
  12.     procedure FormCreate(Sender: TObject);
  13.     procedure DrawButtonClick(Sender: TObject);
  14.  
  15.   private
  16.     FNumbers: TList;
  17.     FDrawnNumbers: TList;
  18.     procedure InitializeGrid;
  19.     procedure DrawNumber;
  20.     procedure HighlightNumber(Num: Integer);
  21.  
  22.   public
  23.  
  24.   end;
  25. var
  26.   MAINFORM: TMAINFORM;
  27.   FDrawnumbers: TList;
  28.  
  29. implementation
  30. {$R *.lfm}
  31. { TMAINFORM }
  32.  
  33. procedure TMAINFORM.FormCreate(Sender: TObject);
  34. begin
  35.   FNumbers:= TList.Create;
  36.   FDrawnumbers:= TList.Create;
  37.   InitiakizeGrid;
  38. end;
  39.  
  40. procedure TMAINFORM.InitializeGrid;
  41. var
  42.   i, j: Integer;
  43.   Num: Integer;
  44. begin
  45.   BingoGrid.ColCount := 10;
  46.   BingoGrid.RowCount := 8;
  47.   BingoGrid.FixedCols := 0;
  48.   BingoGrid.FixedRows := 0;
  49.   for i := 0 to BingoGrid.RowCount - 1 do
  50.     for j := 0 to BingoGrid.ColCount - 1 do
  51.     begin
  52.       Num := i * BingoGrid.ColCount + j + 1;
  53.       BingoGrid.Cells[j, i] := IntToStr(Num);
  54.       FNumbers.Add(Pointer(Num));
  55.     end;
  56. end;
  57.  
  58. procedure TMAINFORM.DrawNumber;
  59. var
  60.   Index: Integer;
  61.   Num: Integer;
  62. begin
  63.   if FNumbers.Count = 0 then
  64.   begin
  65.     ShowMessage('No numbers left!');
  66.     Exit;
  67.   end;
  68.   Index := Random(FNumbers.Count);
  69.   Num := Integer(FNumbers[Index]);
  70.   FNumbers.Delete(Index);
  71.   FDrawnNumbers.Add(Pointer(Num));
  72.   HighlightNumber(Num);
  73. end;
  74.  
  75. procedure TMAINFORM.DrawButtonClick(Sender: TObject);
  76. begin
  77.    DrawNumber;
  78. end;
  79.  
  80. procedure TMAINFORM.HighlightNumber(Num: Integer);
  81. var
  82.   i, j: Integer;
  83. begin
  84.   for i := 0 to BingoGrid.RowCount - 1 do
  85.     for j := 0 to BingoGrid.ColCount - 1 do
  86.       if BingoGrid.Cells[j, i] = IntToStr(Num) then
  87.       begin
  88.         BingoGrid.Cells[j, i] := '[' + BingoGrid.Cells[j, i] + ']';
  89.         BingoGrid.Canvas.Brush.Color := clYellow;
  90.         BingoGrid.Canvas.FillRect(BingoGrid.CellRect(j, i));
  91.         BingoGrid.Canvas.TextOut(BingoGrid.CellRect(j, i).Left + 10,
  92.                   BingoGrid.CellRect(j, i).Top + 10, IntToStr(Num));
  93.       end;
  94. end;
  95.  
  96. end.                        


Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #17 on: August 16, 2024, 11:49:21 am »
The code is also wrong. It is not AI in the sense that is machine generated code, It is AI in the sense that it looked up a silly implementation.
BTW, if you approve of my artwork, I will finish my bingo application and post it here.
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

seghele0

  • Full Member
  • ***
  • Posts: 201
Re: BINGO application
« Reply #18 on: August 16, 2024, 02:07:39 pm »
All solutions to obtain a solid 'Bingo' program are welcome.  :)
A succession of numbers shown in one line is difficult to keep track of when someone has Bingo and the numbers need to be checked.
If the drawn numbers are visible in a kind of grid, then it is much clearer.
Please take your time as there is no urgency.
In the meantime I use the wooden blocks.

If you live in Ukraine, I can confirm that there are several refugees living in my village.
These people do not cause any problems in our society and they are allowed to stay.
 ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #19 on: August 16, 2024, 02:45:26 pm »
But my second example does just that. While working on the code for the GUI app I has to change it a liitle ( not! algorithmically to this:
Code: Pascal  [Select][+][-]
  1. { this is the logic I use in the GUI version based on my secong example }
  2. uses math;
  3. var
  4.   a:array of byte;
  5.   r:array[0..4,0..4] of byte;
  6.   i,j,k,l,t:cardinal;
  7. begin
  8.   { initialize }
  9.   setlength(a,75);
  10.   for i := 0 to high(a) do a[i] := i;
  11.   randomize;
  12.   { bingo cards are 5x5 }
  13.   i := high(a)+1;
  14.   for k:=  0 to 4 do
  15.     for l := 0 to 4 do
  16.     begin
  17.       dec(i);
  18.       j :=randomrange(1,i);
  19.       t:=a[i];a[i]:=a[j];a[j]:=t;
  20.       r[k,l]:=a[i]+1;
  21.     end;  
  22.   { this part in not in the GUI app. }
  23.   writeln('B':3, 'I':3,'N':3,'G':3,'O':3);
  24.   for i := 0 to 4 do
  25.     for j:= 0 to 4 do
  26.     begin
  27.       write(r[i,j]:3);
  28.       if j = 4 then writeln;
  29.     end;
  30. end.
Reason is that I can directly map to a drawgrid, because the 2 dimensional array is prepared.
Almost finished.
« Last Edit: August 16, 2024, 07:44:04 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

seghele0

  • Full Member
  • ***
  • Posts: 201
Re: BINGO application
« Reply #20 on: August 16, 2024, 04:12:12 pm »
Can you please send me the necessary final units (.pas + .lfm + .lpi +.lpr) so I can compile it on Lazarus.
Thanks.

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #21 on: August 16, 2024, 06:17:24 pm »
IT IS A COMPLETE PROGRAM!
The examples are for the console/terminal.
The GUI app will follow later this weekend.

How could you have missed all my examples are complete programs?
The GUI program will look better and has more options.
But the core is like the screenshot shows: that is merely a demo that the algorithm works.
(examples two and three have the same output, randomized, and following the wiki entry about Bingo )

One more question: do you want me to make sure that after every completed draw there is a winner?
That means I have to provide for one line extra code.
I will explain this briefly:
- A Bingo card is a randomized selection of 25 unique numbers out of 75.
- By default it is not guaranteed that the winning card is always present. It is even not likely it is present because of chance.
- But I can make sure the winning card is always present....at least once...
- By a randomized selection of the number of players and then giving the randomly selected player the initially randomized winning card.
All this can be done with just the examples 2 and 3 that I gave you and one line extra..
Writing a graphical user interface takes more time than writing the actual algorithm and is to me just a bit boring.
I did not study computer science to be a screen drawer.
( I wrote my first example in real time while answering your question and that also works, with some oversights corrected in 2 as Zvoni pointed out.. :-[ )

Can you follow all that?
When you answer the question the code is ready tomorrow. I documented the code very well, since you are a beginner.
« Last Edit: August 16, 2024, 07:45:51 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

seghele0

  • Full Member
  • ***
  • Posts: 201
Re: BINGO application
« Reply #22 on: August 17, 2024, 10:23:40 am »
I'ill try to make it clearer how we play Bingo.
The number of participants usually varies between 25 and 45 people.
We already have pre-printed Bingo cards (see attachment) with 24 numbers on each card.
This is a set of 50 cards, with at least 2 different numbers on each card.
So, some cards have more than 20 identical numbers.
Since there are 75 numbers available in the game, there will always be at least one winner during or at the end of the game.
Every time a number is applied, it becomes visible on the screen, and I would like to see clearly which numbers have not yet been chosen and which have.
It's also possible that there is more than one winner, but this depends on the random numbers on the cards.
Once there is a winner I can check on the screen if it is correct.
If you have any questions, please let me know.
Thanks in advance.
 ;)

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #23 on: August 17, 2024, 04:14:46 pm »
That is how I interpreted it and I am making good progress:
- alt-d draws a number and dispLays it in the grid and Separately as large.
- alt-p prints a number of unique cards, number from the print dialog.
- alt-x quits
- alt- t toggles between '"alsways a winner" and "better luck next time"
- alt-m toggles a mistery number in the center of the grid that counts as a free - any number.
- alt-b prints bingo! (actually plays a gif animation)

The code is still simple and I made sure it is well documented (that takes most of the time )

I expect today, but I have guests, so maybe tomorrow.  :)

It is, of course, cross-platform.

Two and a half more questions:
1. I can add sound?
2. Maybe a small database for the participants?
2 and the half: it is easy to create a webserver with the code I have so far, bit more work but may be nice if somebody is ill disposed. ( That is NOT what I will implement right now)
« Last Edit: August 17, 2024, 04:41:06 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

Thaddy

  • Hero Member
  • *****
  • Posts: 15496
  • Censorship about opinions does not belong here.
Re: BINGO application
« Reply #24 on: August 17, 2024, 04:46:59 pm »
BTW in Bingo, the lucky number cell is 13. That is the center.... :D
And that can in theory cause two winners, I suggest who calls first.... 8-)
« Last Edit: August 17, 2024, 04:48:33 pm by Thaddy »
My great hero has found the key to the highway. Rest in peace John Mayall.
Playing: "Broken Wings" in your honour. As well as taking out some mouth organs.

dseligo

  • Hero Member
  • *****
  • Posts: 1334
Re: BINGO application
« Reply #25 on: August 17, 2024, 06:04:32 pm »
2. Maybe a small database for the participants?

I won't comment on other issues because I don't know exact rules of this game, but (IMHO) database (or some file) is almost a must. Not for participants, but for recording state of the game. If game last for some time (one or two hours) it's possible that power runs out or computer resets or something, and it's very annoying if you lost progress of game.

So, after every draw you save state, at the end you clear it. At start of program you check if there is recorded state and offer to start new game or continue old one.

seghele0

  • Full Member
  • ***
  • Posts: 201
Re: BINGO application
« Reply #26 on: August 17, 2024, 06:49:43 pm »
It is no problem if there are two or more winners at the same time.
It doesn't matter who calls first or last.
 :-[
All these winners will receive a small gift.

dbannon

  • Hero Member
  • *****
  • Posts: 2999
    • tomboy-ng, a rewrite of the classic Tomboy
Re: BINGO application
« Reply #27 on: August 18, 2024, 08:13:44 am »
That is how I interpreted it and I am making good progress:
...
- alt- t toggles between '"alsways a winner" and "better luck next time"
- alt-m toggles a mistery number in the center of the grid that counts as a free - any number.

I am not sure you should change the mode, mid game or even while on screen. A risk that an accidental press affects the outcome with everyone being aware could create an ugly situation.  I think the "modes" needs a separate dialog  that cannot be accidentally triggered.

Also, the modes currently toggled with Alt-T might be better called "Always a winner" and "The house might win".

Just my thoughts.
 
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: 201
Re: BINGO application
« Reply #28 on: August 18, 2024, 10:00:23 am »
dbannon
Thank you for your concern, but an unexpected press of the 'next number' button shouldn't be a problem. The only problem is that there might be an extra winner.
Our senior groups are not professional Bingo players.
 ;)


paweld

  • Hero Member
  • *****
  • Posts: 1182
Re: BINGO application
« Reply #29 on: August 18, 2024, 12:54:18 pm »
My proposal, I hope it complies with the rules of the game
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018