I am trying tic-tac-toe game with multi-dimensional array. I saw many posts online but almost all use single dimensional and frankly, I didn't really understand the portions regarding detecting the best moves.
It is an API (with no interface) so interaction is using GET method. So first time server/computer makes the move, the response will be:
****s****
where * is empty square and s is moves by server. then user might reply with
u***s****
and so forth. I have implemented the logic of checking if the move is allowed and if allowed, to reserve the spot.
But I am stuck at deciding where the server should move after the player makes his move even though I have his latest x,y coordinates (or the square in the multi-dimensional array):
Expand|Select|Wrap|Line Numbers
- board =[
- ['*','*','*'],
- ['*','*','*'],
- ['*','*','*'],
- ]
Expand|Select|Wrap|Line Numbers
- board =[
- ['*','*','*'],
- ['*','s','*'],
- ['*','*','*'],
- ]
Expand|Select|Wrap|Line Numbers
- board =[
- ['*','*','*'],
- ['*','s','*'],
- ['u','*','*'],
- ]
Here is what I have attempted so far
1. get all empty squares and save them
2. get neighbors of the last move made (2,0) and for each square that is empty, decide to make server move.
While I have gotten empty squares and neighbors, I don't know how to use them or if they are needed even.
Any help please.