Let’s not just connect 4. Let’s connect what you have learned about arrays and everything that brought you to this point to develop your first AI game in java.
- What does “your” simplified flowchart for a game look like?
2. Let’s talk about “your” algorithm.
3. Use your “Toolkit” from previous lessons:
- You learned how to add rows:
int total = 0; for (int i = 0; i < COUNTRIES; i++) { total = 0; for (int j = 0; j < MEDALS; j++) { total = total + counts[i][j]; } }
- You learned how to add columns:
int total = 0; for (int j = 0; j < MEDALS; j++) { total = 0; for (int i = 0; i < COUNTRIES; i++) { total = total + counts[i][j]; } }
And accessing the neighboring elements of a 2D array
and from Magic Square
You learned how to add diagonals:
sum = 0; for (int i = 0; i < square.length; i++) { sum += square[i][i]; } sum = 0; for (int i = 0; i < square.length; i++) { sum += square[i][square.length-i]; }
4. Add details to your simplified flowchart. Let's develop the "computer to win" a bit further. You do not want to play against an infallible player (the computer) because you will not even want to play the game. So a better approach would be a good blend of random moves with smart moves. You decide how "smart" the computer is.
5. Levels of difficulty. Choose the "Medium" level of difficulty and start the same as in the first game. Do the same for "Hard" level and compare to easy and medium. How different are the behaviors of the "computer" moves? Can you find a pattern?