article

GoMoku for Delphi - How It Works

Email
Submitted on: 1/1/2015 9:49:00 AM
By: Peter E. Williams (from psc cd)  
Level: Intermediate
User Rating: By 5 Users
Compatibility: Delphi 5, Delphi 4, Pre Delphi 4
Views: 2275
 
     This article was written to be read in conjunction with my GoMoku game. It explains the game, the code and why I did things the way that I did. You will find GoMoku v0.04 in the Delphi / Games section.

 
				



Go-Moku Game - My Approach To Writing It In Delphi


Go-Moku Game
My Approach To Writing It In Delphi

by Peter E. Williams

I have written version 0.04 of my GoMoku game. Over the next few weeks I will re-write this article. Previously version of GoMoku had some flaws in the calculation of the weights. I believe that this version is perfect !!! (or as near as we can get).

With Co-ordinate weighting on - on a blank board the cells are weighted according to the X,Y co-ords e.g. the corners (1,1), (1,15), (15,1), (15,15) all have weights of 2 = 1 + 1. The centre cell 8,8 has a weight of 16 = 8+8.

To see the highest cell weighting, do the following: Press D (for "Don't move mode"), then lay down a snowflake pattern (see below e.g. an asterisk with 8 legs of 4 Xs), and press W to see weights. You can then pick viewing weights for either X or O player.

This is the "snowflake" test pattern.

X...X...X
.X..X..X.

..X.X.X..
...XXX...
XXXX?XXXX
...XXX...
..X.X.X..
.X..X..X.
X...X...X

Assuming Offence First ... (e.g. Offensive move rate a little higher than defensive moves)

For the X player, with the centre ( "?" ) of the snowflake being 8,8, the highest weight will be cell 8,8 is:
= (((5^8)+90)*8)+16 = 3125736 (add 90 because the pieces are Xs and we are looking at the X move and *8 because there are 8 legs in the snowflake pattern. +16 because 16 is the rating for the X,Y co-ords for 8,8 e.g. 8+8 = 16)

For the O player, with the centre ( "?" ) of the snowflake being 8,8, the highest weight will be cell 8,8 is:
= (((5^8)-90)*8)+16 = 3124296 (subtract 90 because the pieces are Xs and we are looking at the X move and *8 because there are 8 legs in the snowflake pattern. +16 because 16 is the rating for the X,Y co-ords for 8,8 e.g. 8+8 = 16)

New to ver 0.04

On www.planet-source-code.com I was made aware of a bug in my GoMoku program with the way it calculated the weights. As a result I have rewritten completely the "procedure check_any_direction_for_blank" and I have removed the "procedure check_any_direction_for_piece" (and the procedures that called it) -- as these are no longer required. The other changes are: new "procedure check_for_winner" and "procedure count_pieces_in_line" (which is called by check_for_winner).

Also new is the Tactics menu and "Game / Do Statistics Test" (press T) menu. The "Tactics" menu lets you pick from 3 boolean options (for the tactics the computer uses to weight it's moves): (a) Defence First (unless winning) / Offence First, (b) Use Co-ordinate weights (yes/no), (c) Weight 4 Blocked (e.g. whether in OXX_XO the "_" is weighted or not).

To use the Statistics Test press T and pick which of the tests you want to do e.g. there is a max of 8 tests to perform (8= 2^3). And also enter the number of games for each test. Total number of games in the tests = Number of tests to perform x Number of games for each test. e.g. 8 tests x 10 games = 80 games total. A report will be displayed in a richedit memo after the tests have finished.

Please do not use GoMoku versions before this version (as they are buggy) :-)))



Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.