代写ICS 32 Project 2: Connect 4代写Python编程

Project 2: Connect 4

Due date and time: Wed, 2/19/25, 11:59 pm 

Checkpoint: Wed, 2/12/24, 11:59 am

iGPT AI Assistant: https://nextjs-chat-mu-olive.vercel.app/

Available for all students M-F before 8am & after 5pm, all day Sat/Sun

Overview

For this project, you will implement three versions of a Python console-based Connect Four game:

1. 2-player mode 

2. 1 player vs. AI 

3. 1 player vs. internet AI

Project Goals

1. Implement each mode separately in its own Python file.

2. Reuse as much code as possible across the different versions.

3. Do not modify the provided connect4.py game logic.

Game Details

● Traditional Connect Four Rules

○ Connect Four is a 2 player game where one is red and the other is yellow.

○ Players take turns to drop or pop a disc of their color.

○ Connect 4 discs of your color horizontally, vertically, or diagonally to win.

○ If you're not familiar with the rules of the game, you can review the rules on Wikipedia's Connect Four page.

● Variation

○ Implement both traditional rules and the "Pop Out" variation.

○ At each turn, you can pop out (remove) a disc of your color from the bottom row of the board instead of dropping another disc in.  

● Flexible Board Sizes

○ Support board sizes from 4x4 to 20x20.

● Red Moves First:

○ Red player always moves first.

Getting Started

● From the project 2 folder, download the project2_starter.zip file containing  starter files shown below. Unzip the file and place all starter files into the same working directory.  

 

● A client_short.py file will be provided after lab 7’s due date.

○ This file is only required for the part 3 of this project.

● Read the provided code to understand how the game logic works

Program 1: Local 2-player Game

Functionality:

● Allow two players to play Connect Four using Python shell.

● To start, ask users to specify the board size before starting the game.

● At each turn, display the current state of the board and indicate whose turn it is.

● Clearly instruct users on how to specify the board size and make moves.

● Allow column selection using numbers (e.g., 1 for the far-left column).

● Validate moves and handle invalid inputs gracefully, providing error messages as needed.

● When the user is asked to specify a move but an invalid one is specified (such as dropping into a column that is full), an error message should be printed and the user should be asked again to specify a move. In general, erroneous input at the Python shell should not cause the program to crash; it should simply cause the user to be asked to specify his or her move again.

○ Ex: “Invalid Move”

● The game proceeds, one move at a time, until the game ends, at which point the program ends.

Requirements:

● connect4.py, which contains the provided connect four game logic.

○ Note: You must not modify this module but build your game on top of it.

○ Recommendation: Read through the provided code, docstrings, and comments to understand how the game logic works.

○ Experimentation: Use the Python shell to experiment with the module and comprehend its functionalities.

● connect4_ui.py, which contains utility functions for the 2 player game. The  required functions are described below. You can create additional helper functions as appropriate:

○ make_new_game()

■ Asks the user for the number of rows and columns.

■ The number of rows and columns can be from 4 to 20.

■ Once the user provides valid rows and columns, create new game and return the connect4.Gamestate

○ print_board(state)

■ Returns a string holding the contents of a game board, given a GameState

■ The string should contain all lines of the appropriate display

■ An example board display is shown below

● Note the spacing difference when the column number requires 2 digits.

■ If it’s red’s turn, display “RED’s turn” after the board

■ If it’s yellow’s turn, display “YELLOW’s turn” after the board

■ If red wins, display “RED wins!”

■ If yellow wins, display “YELLOW wins!”

○ choose_move(state)

■ Asks the user to choose a move, returning a tuple whose first element is DROP or POP and whose second element is a valid column number.

■ Asks the user for a move, should only return a valid move

■ Keep asking user if wrong move type or column is detected

○ make_move(state, move)

■ Makes the given move against the given state, returning the new state.

■ For a valid move, return the new state.

■ Raise connect4.InvalidMoveError if invalid operation detected.

■ Implement exception handler to catch this exception. If connect4.InvalidMoveError exception is caught, return the original state.

● connect4_console.py, which implements the 2-player game.

○ All code should be implemented inside the provided run_console_ui() function.

○ Utilize functions defined in connect4 and connect4_ui modules.

○ If a move is illegal, such as dropping a disc into a full column or popping a column where the bottom disc is not the player’s color, the program should indicate “Invalid Move” and ask the same player for another move. This applies to both players.

Here is an example of a game with 20 columns and 5 rows:

Here is an example of how Pop works:


Program 2: 1 Player game against AI

Functionality:

● Allow a human player (red) to play against an AI player (yellow).

● AI is always the 2nd player in yellow.

● Maintain the same user interaction and board display rules as in Program 1.

● Implement a simple AI based on random selection.

● Extra credit: implement a more sophisticated AI for the Connect 4 AI Tournament. More details provided later in the document.

Requirements:

● connect4_ui_ai.py, which implements the ai player functionality.

○ ai_move(state)

■ Takes connect4.GameState as input

■ Asks the AI to choose a move, and the AI will return a tuple with the following format (move, column number).

■ The move is either DROP or POP, which are constants defined as 1 for DROP and 2 for POP

■ The column number should be from 1 to the number of columns for the board.

■ For full credit, you can simply implement the AI with random numbers.

● For extra credit, you can implement a more complex AI for the ICS 32 Connect 4 AI Tournament. More details are presented at the end of this doc.

■ Note: the AI only needs to return a tuple consisting of a valid move and a column within the valid range of columns. The entire move may still be invalid due to certain circumstances. We will address this issue inside of connect4_console_ai.py.

■ Hint: helper functions would be useful here.

● connect4_console_ai.py, which implements the 1 player game against AI

○ All of the code needs to reside inside the run_console_ui() function.

○ Utilize functions defined in connect4, connect4_ui, and connect4_ui_ai.py modules.

○ If a move is illegal, such as dropping a disc into a full column or popping a column where the bottom disc is not the player’s color, the program should indicate “Invalid Move” and ask the same player for another move. This applies to both the human and AI players.

Program 3: Networked Connect 4 vs Server AI

Functionality:

● Play Connect Four against an AI server over the network, by connecting to a server that I will provide.

● Your program will act as a client that connects to a server.

● When this program starts, the user will need to specify the host (either an IP address, such as 192.168.1.101, or a hostname, such as www.ics.uci.edu) where a Connect Four server is running, along with the port on which that server is listening.

● Once the user has specified where to connect, the program should attempt to connect to the server. If the connection is unsuccessful, print an error message specifying why and end the program. If, on the other hand, the connection is successful, the game should proceed, with the client acting as the red player (and moving first) and the server AI acting as the yellow player. (Of course, the user will need to specify the size of the board before the game starts.) For red player moves, the user should specify the move at the Python shell, as in your first program; for yellow player moves, the program should instead communicate with the server and let the server determine what move should be made.

● As in the first program, the game proceeds, one move at a time, until the game ends, at which point the program ends.

● User Inputs:

○ Host (IP address or hostname) where the server is running.

○ Port number of the server.

● Connection Handling:

○ Attempt to connect to the server.

○ If the connection fails, print an error message and end the program. If successful, proceed with the game.

● Game Interaction:

○ The red player (user) specifies moves, while the server determines yellow player moves.

○ Follow the same move validation and error handling practices as in Program 1.

● Protocol

○ Need to follow the CFSP protocol to be described later in this document.

Requirements:

● client_short.py, which implements the networking functions via sockets.

○ You should have implemented this during the lab.

○ We are providing fully functional networking code for you to utilize.

○ Do not change the code in this file.

● connect4_network_client.py, which implements the game vs the internet AI.

○ All of your  code needs to reside inside the run_console_network() function.

○ Utilize functions defined in connect4, connect4_ui, connect4_ui_ai.py, and client_short modules.


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图