159k views
5 votes
#For this check-in, your goal is to write an agent that can

#play tic-tac-toe.

#

#How do you code an agent that plays tic-tac-toe? Well, you

#code an agent that plays a single move in a tic-tac-toe game.

#Then, we run a game, passing the board back and forth between

#your agent and an opponent.

#

#So, all you need to do is write a function called move. move

#should have one parameter, a list of lists. The parameter

#will always be a 3x3 list of characters. Every item in the

#3x3 list will be either a space (empty), U (Us), or T (Them).

#We're using U and T instead of X and O so that your agent

#doesn't have to worry about whether it's playing as X or O:

#you always play as U.

#

#Your move function should always return a tuple with two

#integer representing the coordinate where you want to play, row

#then column. For example, returning (0, 0) would play in the

#top left. Returning (0, 2) would play in the top right (row 0,

#column 2). Returning (2, 0) would play in the bottom left (row

#2, column 0). Returning (2, 2) would play in the bottom right

#(row 2, column 2).

#

#Remember, you're only coding an agent to play a single move

#in a tic-tac-toe game; it's given a board and it returns a

#single move. The board it receives might be empty, it might

#be partially-played, or it might have only a single possible

#move remaining. You may assume that the game board is valid

#(e.g. no one has yet won the game).

#

#In order to pass this check-in, all you have to do is write

#an agent that can play a move in any valid board: it never

#tries to play in a spot that has already been played or to

#play a move out of range. Beyond that, it does not matter if

#your agent wins or loses, or how it selects the move to play.



#Add your move() function here!

Please help me, I've been working on this for HOURS and about to cry

User Stratis
by
4.3k points

1 Answer

3 votes

Final answer:

To code an agent that plays tic-tac-toe, you need to write a function called move() that takes a 3x3 list representing the game board as a parameter. The function should return a tuple with two integers indicating the coordinate of the move.

Step-by-step explanation:

To code an agent that plays tic-tac-toe, you need to write a function called move(). This function takes a 3x3 list as a parameter, representing the game board. The list contains characters, with each item being either a space (empty), U (representing your move), or T (representing the opponent's move). The goal of the function is to return a tuple with two integers indicating the coordinate of the move, specifying the row and column.

For example, if you want to play in the top left, you would return (0, 0). If you want to play in the bottom right, you would return (2, 2).

Remember, the game board might be empty, partially played, or have only one move remaining. Your agent should not try to play in a spot that has already been played or make a move out of range.

User Cosmin SD
by
4.8k points