473,468 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

finding best move in a multi-dimensional array driven tic-tac-toe game

228 New Member
Hi,

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
  1. board =[
  2.         ['*','*','*'],
  3.         ['*','*','*'],
  4.         ['*','*','*'],
  5.        ]
  6.  
  7.  
This is the structure of the board/array. First state is going to be, example server makes the move:

Expand|Select|Wrap|Line Numbers
  1.  
  2. board =[
  3.         ['*','*','*'],
  4.         ['*','s','*'],
  5.         ['*','*','*'],
  6.        ]
  7.  
  8.  
then player mokes a move

Expand|Select|Wrap|Line Numbers
  1.  
  2. board =[
  3.         ['*','*','*'],
  4.         ['*','s','*'],
  5.         ['u','*','*'],
  6.        ]
  7.  
  8.  
when he made the move, I have 2,0 saved in variables but am really clueless on how to determine the next smart/best move.

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.
Nov 21 '18 #1
1 1415
gits
5,390 Recognized Expert Moderator Expert
well - while this is not a javascript question but more an algorithm question you can start from here:

https://medium.freecodecamp.org/buil...e-29d4d5adee07

for example. This explains a bit the solution that this implementation used - so you have to adapt it to your own implementation.
Nov 21 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: bijax | last post by:
hi, i am new to multidimensional array of c programming .pls help me to solve out this how to allocate memory for mutidimensional array? i.e a ;
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
4
by: Gregory.A.Book | last post by:
I'm working with displaying and manipulating very large image sets. The program handles anything from 2D images to 4D RGB volumes in a time-series. I've been using dynamically allocated arrays to...
5
by: TS | last post by:
is there some code somewhere that does this? i have a jagged array that is not jagged, it has an equal number of rows and columns in each array so it should convert but want to get the code to do...
2
by: phattymatty | last post by:
I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensional array in order. The order has already been sorted in the array using a...
23
by: drazet | last post by:
hi,all i have a question about multidimensional array. int w,(*pw); pw=w; is *(pw+1) wrong?why? and *(w+2),pw and *(pw+2) mean?
1
by: shailajaAdiga | last post by:
Hi All, there are 4 different categories which each month will bw updated. In each category(source),there are many editions. I have to display 6months updates. its like one is month array which...
2
Brandenburg
by: Brandenburg | last post by:
I'm writing a game in visual basic 2008 and things are going fairly well with it for the most part.. well until today.. I can declare a 1 dimensional array of a class just fine but cannot for the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.