|
-
Nov 4th, 2002, 06:27 AM
#1
Thread Starter
New Member
Connect4
I am trying to create a 2 dimensional 1 player versions of the board games connect4, and battleships. Has anyone got any ideas on how the games Ai will be developed, to allow a player to play against the computer.
Your help will be most appreciated.
-
Nov 4th, 2002, 04:21 PM
#2
Fanatic Member
player 1 is 1
player 2 is 2
Firstly decide what size your grid is going to be. Each position on the board could be an array element of a 2D array.
Each time a player puts a piece on the board iterate through the array noting which players piece is in which slot.
your array in memory would look like this
--------
--------
--------
1-------
12--2---
11221---
Then starting at the bottom left look at the one above if it is the same look at the one above if it is the same look at the one above, then look at the one above that. there are only three number 1 in the vertical column on the left, not a winner so use the same method with the position up to the right diagonally, in the example it is a 2. Not a winning line, check the position to the right, it is a one , check the position to the right again, that is a 2 so not a winning row.
Now use the same method starting with the second position from the left on the botton row. check the left (West) then North west, then north, north east and east.
if the next one you are checking with is the same as the one you are currently on increase the count by one. if you reach a count of 4 you have a winner.
Remember when you move onto the second row you must check all directions.
You display on screen a graphical version of the contents of the array.
I hope I have explained this well enough for you.
-
Nov 4th, 2002, 04:50 PM
#3
The AI for battleships is easy: fire at random positions or fill a grid, when you score a hit fire at the sourrounding fields. The AI needs to find lines and follow them.
When you have special rules, like that ships may not be adjacent to each other, the AI should mark those fields hit (and empty) too to make sure no unnecessary shots are fired.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 4th, 2002, 04:52 PM
#4
A good AI for Connect4 is far more complex. It needs to have a strategy for building traps, and it should (if it's good) see enemy traps a few turns ahead and play to avoid them. I have no idea how to do that.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|