Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
EECS 492 - Homework 2 (Fall 2024)
Logistics
Submission Guidelines
The due date for this assignment is October 25, 2024 at 11:59pm. The submission is tracked using Gradescope. The written section and programming section are graded and penalized separately. Also note that any change you make to the homework already submitted on Gradescope counts as a resubmission.
You must submit the following ! les to Gradescope (note that there are two separate Gradescope submissions):
- A legible PDF containing the solutions to the written section. You can write your solutions by hand, use a tablet, or typeset your solutions in LATEX. We only ask that you make it easy to read and not too verbose so that graders don’t struggle to understand your writing. You must submit the written section to the Gradescope individually.
- The completed Agent.py ! le to the programming section.
Grading Policy
2 Programming Section [50 Points]
2.1 Setup
We highly recommend creating a new virtual environment for the assignment under the Coding folder. You can then simply install the requirements by running the command python -m pip install -r requirements.txt
2.2 Problem Statement
The assignment folder contains these ! les:
- Agent.py
- Game.py
- TTT.py
- Connect4.py
- requirements.txt
The relevant function here is:
- minimax(self, board, depth, maximizingPlayer, alpha, beta): this is a recur sive function for which you must complete the implementation. You must complete this function using pruning, as regular minimax will take too long to run. When implementing the function, it is important to break ties by prioritizing winning in the fewest moves (losing with as many moves as possible). The output of this function is the move made and the score.
- turn: this variable decides whose turn it is, the human or AI. It is randomly initialized to one of the players in the main method. However, if you are ! rst testing your implementation, you may want to initialize it to a speci! c player for consistent results.
Both ! les implement their respective games and share important function names for easy implementation of the minimax function. You should not modify these functions, but familiarize yourself with them, as they might be useful in writing minimax.
- get_valid_moves(board): returns list of columns/coordinates where a move can be made based on current board.
- play_move(board, move, player): makes a deep copy of the board and returns the updated board with the new move made by a player.
- heuristic_value(board, player): calculates and returns the score for a player based on that player’s moves.
- is_winner(board, player): boolean function that determines if either player has put their game piece in 3 consecutive cells for TTT, or 4 consecutive cells for Connect 4
- is_full(board): boolean function that returns if the board is full
2.3 Testing locally
To try your code without tests, you can run python Game.py TTT or python Game.py C4.
To try the test cases for C4, you can run python Game.py C4 test[n].txt where n is the test number from 0 to 3. In expected_results.txt, you will see the columns you need to make your move as the human, how many moves it should take the agent to win, and the winning combination stated by its row and column location. Test cases 1, 2 and 3 are identical on Gradescope. There are no hidden test cases - your score on Gradescope is the score you can expect to receive for this section.