Sign in to follow this  

TicTacToe Game State

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have seen the threads about game states and thought that was a bit beyond both myself and the scope of TicTacToe. I have just been thinking about how I am going to represent the state of the TicTacToe board throughout the game. This state will passed to the MiniMaxAB algorithm as a means of determining the computers next best move. I have been considering two options: 1. A 3x3 Array - threes rows of three columns just like to board. This way, it will be easy to see in the code what is going on e.g. board[1][2] will obviously represent the location in the first row, second column. 2. A 9 element array - where index 0 = pos(1,1), 1 = pos(1,2),..., 8 = pos(3,3) This approach just seemed like an alternative that should be considered. What do people think? Am I going about this the wrong way? Any and all comments will be most appreciated! Thanks, J-Ral!

Share this post


Link to post
Share on other sites
The 9-element array is typically a bit nicer for UI, since you don't have to calculate row and column values to locate the player's move (or worse, ask the user for two numbers in order to make a move). However, it's not necessarily as intuitive.

Keep in mind that you also need to think about how to store the state of each square. If you are going to be outputting stuff to the console, my strong recommendation is to have each tile state represented by a single character which is the one that you will output on display: 'O' or 'X' for occupied squares, and values '1' through '9' for vacant ones. (Try to frame all your tests for square state in terms of presence/absence of 'O' or 'X', rather than checking for the digit values.)

Share this post


Link to post
Share on other sites
I like the 9 element array myself, as you can pass less data around. For example, to represent a diagonal, you can pass (start at element 2, increase 2 elements each time) instead of 2, 0, -1, 1, (start at 2,0, move -1,1 each time). It's a little less obvious what the heck is happening, but it's simpler (in terms of code at least) in my opinion.

Share this post


Link to post
Share on other sites
Hey people,

Thanks for the input!

Just so you know, I am using Visual Basic.NET to program TicTacToe just to begin with so that I can concentrate on the game code as opposed to taking ages to perfect the UI.

So input from the user will be handled by label click events etc. which will in turn give the appropriate square (represented by place in either a 3x3 array or 9 element array) a value of 1 or 2.

The value's for each square are 0 (meaning empty), 1 (meaning occupied by player1) and 2 (occupied by player 2).

The game state evaluation function will simply test the values of squares to check for certain conditions which define the 'goodness' of the game state (from the PC's perspective that is).

With that in mind, I think one of the biggest determining factors in deciding whether to use a 3x3 or 9 element array will be the implications that surface wilst testing for winning conditions.

I am confused as to whether checking for winning conditions would be easier, harder or the same for each representation of game state.

What do people think?

Thanks a lot for all your input!

Jral

Share this post


Link to post
Share on other sites

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this