TaRaKa Posted June 11, 2004 Share Posted June 11, 2004 i got board today and made a tictactoe game in c++ the basic of the game is an array int Set[3][3]; and the elements have values 0 for empty 1 for player 1 and 2 for player 2 the computer will be player 2 and i would like to wite a NP script the game works great with 2 human players Link to comment Share on other sites More sharing options...
0 bwx Posted June 11, 2004 Share Posted June 11, 2004 You're on the right track, however I don't see your question. :huh: Post some code you have already written and we will try to help you from there, as no one is going to write the whole thing for you. bwx Link to comment Share on other sites More sharing options...
0 TaRaKa Posted June 11, 2004 Author Share Posted June 11, 2004 the question is about the script for the non player Link to comment Share on other sites More sharing options...
0 TaRaKa Posted June 11, 2004 Author Share Posted June 11, 2004 heres the project if uv got any sugestions then plz help i want to write a computer player script TicTacToe.zip Link to comment Share on other sites More sharing options...
0 bwx Posted June 11, 2004 Share Posted June 11, 2004 From what I understand, you're trying to write some decision-making code for the computer to act as a player. For a tic-tac-toe game this is pretty easy, you just need to check for empty spaces and which spaces would be smart to move into. You can do this with a couple of simple control path's. Assuming player 2 is the computer: if (board[0][0] == 2) { if (board[1][1] == 2 && board[2][2] == 0) { /* move to board[2][2] */ } else if (board[1][0] == 2 && board[2][0] == 0) { /* move to board[2][0] */ } /* ... */ } else if (board[0][0] == 1) { if (board[1][1] == 1) { /* block player 1 from winning */ /* move to board[2][2] */ } else if (board[1][0] == 1) { /* move to board[2][0] */ } } This is just a small example, but it should give you an idea on what path to take. Another problem with these is usually that they always make the best move possible which makes it impossible to win by a human player. If you have any questions on this feel free to ask and I'll try to elaborate. bwx Link to comment Share on other sites More sharing options...
0 TaRaKa Posted June 11, 2004 Author Share Posted June 11, 2004 thanks alot man thats a real help Link to comment Share on other sites More sharing options...
0 justin89h Posted June 11, 2004 Share Posted June 11, 2004 omg, im working on a c++ tic tac toe game as well... with two players... 0 is empty, 1 is player 1, 2 is player 2..... and my board array is called 'set' extremely weird coincidence. Anyway, im no where near putting AI in, im still working out a good system of checking matches. Ill attach my code, and you can see the way ive done things, if you have any interest to. Excuse the simpleness and extremely poor coding style, its a learning experience. :) Anyway, for the computer player script i have some ideas. The simplest, but least effective way would just be to make the computer go in a random un occupied place. What i am planning to do is to program in all the well known strategies (there is only a select few possible) and then make the computer go random for the first shot, then follow the strategy for the rest of the shots. To make it easy, the computer would be random for the first two shots, etc. I havent worked out how to put these ideas into effect, but i think these are effective ideas to make a AI player seem smart. :) nac.cpp Link to comment Share on other sites More sharing options...
0 HeartsOfWar Posted June 11, 2004 Share Posted June 11, 2004 The problem with implmenting A.I into Tic Tac Toe is that it's very easy to make a NPC that is unbeatable and without effort. like all A.I. it's only as smart as the programmer, but of course, with something as simple as Tic tac toe, the A.I won't be that difficult. Certainly not the best game to implement an A.I. unless you make it flawed through randomization, but it is a start. Keep it up and continue moving onto bigger and better projects :) Link to comment Share on other sites More sharing options...
0 anthonycara Posted June 12, 2004 Share Posted June 12, 2004 YEAH, an unbeatable AI is boring. If you want it to be beatable, do a simple 'block then random' script. what a funny co-incidence, i just finished a tictactoe game on the TI83. Unfortunately, my array was called [J], not set. Link to comment Share on other sites More sharing options...
0 TaRaKa Posted June 12, 2004 Author Share Posted June 12, 2004 i have dificulty levels which dictate the probablility of the computer making a random move or a calculated move Link to comment Share on other sites More sharing options...
0 super_serge Posted June 12, 2004 Share Posted June 12, 2004 For the ai, make the computer go in a priority of stopping the opponent and then finishing his own tic tac toe. Make a system where num = rand(1, 10); if (num <= 3) do something smart; else do bullcrap; for varying difficulties Link to comment Share on other sites More sharing options...
Question
TaRaKa
i got board today and made a tictactoe game in c++
the basic of the game is an array
int Set[3][3];
and the elements have values 0 for empty 1 for player 1 and 2 for player 2
the computer will be player 2 and i would like to wite a NP script the game works great with 2 human players
Link to comment
Share on other sites
10 answers to this question
Recommended Posts