EECS 492 - Homework 2 (Fall 2024)

Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due

EECS 492 - Homework 2 (Fall 2024)

Due: October 25, 2024 at 11:59pm

Logistics
Submission Guidelines

IMPORTANT NOTE: It is essential that you read carefully the policies in the Syllabus section on Homework. It discusses what counts as late and how late penalties will be applied. Please also be sure you have read and understand the Academic Integrity section, including the sections on collaboration and the use of generative AI. The Generative AI section also includes a link to an example citation and explanation. You will be held responsible for following these policies, with violations being reported to the Honor Council.

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):

  1. 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.
  2. The completed Agent.py ! le to the programming section.

Grading Policy

Regrade requests must be submitted to Gradescope within one week of when the grades for the item are made available. Later regrade requests will not be accepted. We will provide solutions, along with the exact grading rubric used.

2 Programming Section [50 Points]

2.1 Setup

All programming assignments for this course use Python. If you’re new to Python or not very experienced with it, please come to o" ce hours; we’re happy to help! We recommend checking out the Python section in the Resources document on Google Drive. We have also shared a document Debugging Tips to help you debug your code.

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

For this programming section, you will be working on creating a Tic-Tac-Toe (TTT) AI and Connect-4 (C4) AI. You will be using minimax with 훼훽 pruning in Agent.py to create an agent that will predict the best set of moves to maximize the chances of winning in either game. If you are not familiar with the rules of these games, you can learn about the rules for TTT and C4 here.

The assignment folder contains these ! les:

  • Agent.py
  • Game.py
  • TTT.py
  • Connect4.py
  • requirements.txt
Agent.py

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.
Game.py
This ! le references the two games we have implemented for you, Tic-Tac-Toe and Connect 4, and this is where you will test your implementation with the tests. An important variable is:
  • 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.
TTT.py and Connect4.py

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.

Important functions are:
  • 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
One of the main di# erences in the games is how you view them. Since TTT is quite basic, it can be played in your terminal. Since Connect 4 is a 6x7 grid, we have included code to simulate the game in another window to better visualize the board.

2.3 Testing locally

We have provided four test cases for Connect 4 that you can use to test your implementation. Since Tic-Tac-Toe does not have many solutions, you can test its correctness using the terminal or make your own tests.

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.

To better visualize the local tests, you can view the ! nal board state for each test below
in Figure 2. The dotted line is the winning combination by the agent.

Figure 2: Final board states for the local tests

发表评论

电子邮件地址不会被公开。 必填项已用*标注