Teacher’s Notes:
=======================================
You could make this a much larger assignment by only giving the students the headers for each of the methods I have provided and asking them to write the methods themselves.
At the very least, each student's AI should look for an imminent win and imminent loss and choose the spot that would either finalize the win or prevent the loss. The AI should prioritize a win over a loss if each can be achieved on the same turn.
If both players make their plays completely random, Player 1 will win about 55% of the time. It might be a good discussion as to why. The reason is that player 1 going first has a chance to win before player 2 makes their move. This gives player 1 an advantage. This is why the program varies which player will go first with the variable goesFirst.
It might be fun to set up a whole class tournament with brackets to see who can make the best AI!
Assignment:
=======================================
Connect 4
In this assignment, you will be provided with the code for a game of Connect 4 at:
https://github.com/TaoOfChow/Connect4/blob/main/Connect4.java
This is a two player game. The first player gets red tokens and the second player gets yellow tokens. The players take turns dropping their tokens into a single column of a vertical board. The board has 7 columns and 6 rows. When the token is dropped into a column, it falls until it either comes to rest on the bottom of the board of hit another token from either player. After each turn, the board is checked to see if there is a line with 4 tokens of the same colour that is oriented vertically, horizontally or diagonally in a straight line. If a player manages to create this 4 token line, they win the game.
You and a partner are each to write a method to compete against each other in this game. One of you will write the code for player1Move() and the other for player2Move(). Then, the program will run 1000 games with both of your AI's competing against each other. After the 1000 games, the winner will be declared.