Pergunta

I am planning on making a note and crosses game in java for my final year college project and I was wondering what different types are AI are there that I can benefit from using in terms of shortening my code etc. Currently, I am planning on using series of if, else if, else statements but my guesses are that it will require large amount of code because I will need to check for all the possibilities for example, when checking for wins, I would do something like.

if(button1.getText().equals(button2.getText()) && button2.getText().equals(button3.getText()) && button1.getText().equals("X"))
{

    wining statement.....
}
.....
.....
.....
repeat for all the possibilities of winning,
Foi útil?

Solução

Let's see what you've got. Probably this is a duplicate of a bunch of questions though. It seems you do not have the data structures right yet. I would go with a two dimensional array (or a one dimensional with accessor methods to look like a 2D array), so the individual (named) buttons is a bad idea imho.

After that you should check the tic-tac-toe related questions, I guess you will find some inspiration and the discussion part of your paper will have more voices, opinions. There are many ways to solve this, playing the game a few times you will realize the first user should put its sign to the middle and after that there are not many choices. If you prefer to find these rules automatically, you can use backtracking, alpa-beta cutting, neural network, almost anything that is AI related.

Good luck to this task!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top