Game207

User projects written in or related to FreeBASIC.
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Game207

Postby codeFoil » Apr 24, 2012 17:47

About six years ago, I prototyped a Connect Four game in QuickBasic. I ported it to FreeBASIC soon after, but I lost interest and never polished it up. All of that source code was lost a long time ago. A few weeks ago, I decided to give it another go. This version is "prettier" than the original, but it is much more memory intensive due to a completely different method of seaching the game tree.

The AI heuristic has a quirky personality. It loves to play and will occasionally pass up a sure win to keep playing. I could fix this, but I find it entertaining. It also tends to throw in the towel when it finds that it is going to eventually lose.


Win32 binary: Game207v1.01bwin32.zip
Source : Game207v1.01bSource.zip

The source is pure FB and uses only the RTL and FbGFX.
The code should be pretty robust at this point, but there may be issues in low memory situations, so if you have any issues let be know so that I can figure out how to "crash gracefully".

Update: Due to issues with the file host, I have also placed the project on Sourceforge.
https://sourceforge.net/projects/game207/
Update: Addressed bug discovered by Pestery
Last edited by codeFoil on Apr 27, 2012 2:44, edited 2 times in total.
VANYA
Posts: 1331
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: Game207

Postby VANYA » Apr 25, 2012 3:43

I really liked!
nobozoz
Posts: 238
Joined: Nov 17, 2005 6:24
Location: Chino Hills, CA, USA

Re: Game207

Postby nobozoz » Apr 25, 2012 4:10

Executable .zip file comes in corrupted - tried 2 times, same result. I'm on WINXPSP3 here.
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » Apr 25, 2012 11:19

nobozoz wrote:Executable .zip file comes in corrupted - tried 2 times, same result. I'm on WINXPSP3 here.


Thank you. I'm looking into it.

Looks like an intermittent problem with fileden. Thank you for bringing to my attention.
pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Re: Game207

Postby pestery » Apr 26, 2012 7:51

Cool, lost 2 games, won 1 game, and now I think I've broken it :-)

Debug info, I restarted after having won, I picked black and the AI (as white) made a move. I then decided I wanted to play as white for a change so I restarted and made a move, but then noticed that the AI appeared to have frozen. The interface was still running until I clicked the close button, and then the program froze (had to use task manager to close it).
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » Apr 26, 2012 14:02

pestery wrote:Cool, lost 2 games, won 1 game, and now I think I've broken it :-)

Debug info, I restarted after having won, I picked black and the AI (as white) made a move. I then decided I wanted to play as white for a change so I restarted and made a move, but then noticed that the AI appeared to have frozen. The interface was still running until I clicked the close button, and then the program froze (had to use task manager to close it).


Thanks for the heads up.
Do you recall if the "exit banner" was displayed before the program froze after clicking exit?
I have not been able to reproduce the bug, but I have found that occasionally freeeing the memory allocated during early moves seems to crawl.

Update: I believe I've found the problem. (AI thread was waiting on a signal, and I had cleared the wrong flag when the board resets.). I also noticed an infinite loop issue under specific conditions when a tie is inevitable, and I think I've fixed that as well.
Links above will be changed to the revised files.
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Game207

Postby TESLACOIL » May 01, 2012 18:24

>

The game was solved mathematically by James D. Allen (October 1, 1988), and independently by Victor Allis (October 16, 1988).[3] With perfect play, the first player can force a win by starting in the middle column. By starting in the two adjacent columns, the first player allows the second player to reach a draw; by starting with the four outer columns, the first player allows the second player to force a win.

http://en.wikipedia.org/wiki/Connect_Four


the 6x7 grid can probably be solved by simple brute force search on modern pc's in seconds or minutes

with an opening book of 100 possibilities say 3 or 4 deep brute force will prolly do the rest

ive not done the maths but its an exponentially simpler task than chess


EXPTIME
http://en.wikipedia.org/wiki/EXPTIME-complete
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » May 01, 2012 19:07

teslacoil wrote:the 6x7 grid can probably be solved by simple brute force search on modern pc's in seconds or minutes


Yes, but that makes for a very boring game. I've limited the brute force search to eight moves ahead to allow the opponent to play just well enough. With only seven, it is too easily trapped in the beginning of a game. More than eight provides little playable benefit.
This is probably the simplest board game to implement. The number of possible moves at any given point in the game is never greater than the number of columns on the grid, and the win condition logic involves nothing more than counting, so this is certainly not Strong AI.
badidea
Posts: 1711
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Game207

Postby badidea » May 01, 2012 19:24

Yes, recursively simpler than chess, but still a lot to calculate.

Each turn the maximum number of places to put a coin is 7. For the first 6 turns this number of choices is always 7, so 7^6 possibilities (=117649).

At turn number 7 the number of possible 'coin positions' goes down. Because, no more coins fit in the column, or there is a winner.

Someone else may do the rest of the calculation :-)

BTW: I does not run on Linux.
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » May 01, 2012 19:31

badidea wrote:BTW: I does not run on Linux.

Thank you. I don't have a linux system setup to test with. Is it a compilation issue or an execution error?
TESLACOIL
Posts: 1769
Joined: Jun 20, 2010 16:04
Location: UK
Contact:

Re: Game207

Postby TESLACOIL » May 01, 2012 19:38

ref boring ...yeah i know

i was thinking more along the lines of 'solving it' and using the solved AI as a wall to bounce your AI (or other peoples AI off )


Its the sort of game i need to teach my Generic AI to play, if i give it a big enough memory buffer it could perhaps do a bit of suck it and see brute force exploration.....ultimately a HAL9000 could look at the problem, rub its titanium chin and say gimme 20mins or so and ill have it nailed.

My AI is a bit thick, so it uses a bit of brute force here and there to help it figure out its next move or action. This is more about reducing its learning time, aka needing less practice to wise up
badidea
Posts: 1711
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Game207

Postby badidea » May 01, 2012 19:46

Some googling: 4,531,985,219,092 possible positions in standard 7x6 connect-4.
If each position takes, let's say' 0.1 us, then you still need 126 hours.

About Linux:
I did not know how to use the Game207.fbc file, so I tried to compile main.bas. For this I had to change things like "GUI.bi" to "inc\GUI.bi". Then also some case sensitive problems like "ai" / "AI". And then I got messages like: "main.o: In function `main': (.text+0x90): undefined reference to `GAME_WINDOW::GAME_WINDOW()' ". There I gave up.

I gave it a 2nd try with the Game207.fbc file, but now I get:
Assembler messages:
Error: can't open State\Board_State.asm for reading: No such file or directory

Too confusing for me...
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » May 01, 2012 20:55

badidea wrote:I did not know how to use the Game207.fbc file


That is a command line option "response file". It basically contains a list of command line options for the compiler.
I might need to check on the case of some of the directory names.
Roland Chastain
Posts: 856
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: Game207

Postby Roland Chastain » May 24, 2012 1:28

Hello CodeFoil !

I have just tried your game.
The interface is splendid !
As soon as I can I will have a look into your code.

Roland
codeFoil
Posts: 255
Joined: Dec 22, 2011 4:45
Location: United States
Contact:

Re: Game207

Postby codeFoil » May 24, 2012 20:59

Roland Chastain wrote:Hello CodeFoil !

I have just tried your game.
The interface is splendid !
As soon as I can I will have a look into your code.

Roland


The code is a bit of a mess. I did put a lot of thought into keeping the interface very simple, but I didn't extend that philosophy to the actual source code. The entire project was a test bed for some of the "best practices" literature I've absorbed over the years, but I don't think my application of them could be called the "best". My next project will definitely benefit from what I learned on this one.
Thank you, though, for the kind feed back.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 1 guest