# artificial intelligence

Get help using Construct 2

### » Thu Jan 23, 2014 12:36 pm

Hello,

How can i built tic tac toe game with "artificial intelligence" to play vs computer??

B
11
S
3
Posts: 56
Reputation: 893

### » Thu Jan 23, 2014 12:43 pm

Arrays will help you alot in this situation,Being that a tic-tac-toe board only has 6 slots it should be fairly easy to make logic for such a project.
Arrays are your best friend,trust me i was really depressed before i found my friend Array.It will help you figure out how to draw tiles into slots,That along with basic knowledge of the system and you should have a tic-tac-toe game in no time.
If you need help with something more in depth,you should be more specific.
GMO FOOD = DEATH
B
24
S
9
G
5
Posts: 567
Reputation: 6,418

### » Thu Jan 23, 2014 1:03 pm

actually the game is ready. but game is played by 2 players. i wanna play vs computer. so after my move in game, computer should play according to my move to win me..
how method should i try?
B
11
S
3
Posts: 56
Reputation: 893

### » Thu Jan 23, 2014 5:50 pm

You just need to program in the logic.

If player places piece here, CPU should place piece here. If that spot is taken, place piece here, etc.
B
101
S
32
G
12
Posts: 1,549
Reputation: 22,033

### » Thu Jan 23, 2014 7:00 pm

When it is the computer's turn, check to see if the player has two in a row and block it, otherwise start checking for open spaces in order of best position and fill the first available slot.

no capx so it's hard to give specific example since I'm not going to write one from scratch but I'd check boxes from center, diagonals, then sides for open moves. Not sure what a good strategy for tic-tac-toe would be.

You might be able to find a strategy in this javascript AI example
http://www.javascriptkit.com/script/script2/tactoe.shtml
B
17
S
4
Posts: 31
Reputation: 1,600

### » Thu Jan 23, 2014 7:28 pm

(actually, you would also check to see if the computer player has two in a row, and fill that one as well, and win. possibly using the same "check for two" routine.)
B
248
S
65
G
34
Posts: 906
Reputation: 41,349

### » Thu Jan 23, 2014 8:13 pm

Yeah would be good strategy. Thanks.
B
17
S
4
Posts: 31
Reputation: 1,600