Question: complete the coding portions for 1 c , 1 d , 2 a , and 2 b . you may need to download or lookup

complete the coding portions for 1c,1d,2a, and 2b. you may need to download or lookup the games.py or agents.py in amia-python code.
Problem 1.(30 points)
For problem 1, you will put answers in your writeup for a - c. Also make alterations to the given python module.
a. Run the ps3.py code. You will be prompted to play tic-tac-toe against a minimax agent. Common wisdom suggests that the best first move is the center square. The agent doesnt begin by playing in the center square. Why do you think the agent plays where it does instead of the center? Give an explanation (4-5 sentences) in your writeup.
b. Alter the ps3.py codes main function so that it calls problem 1b instead of problem 1a. You will be prompted to play connect-4 against an alpha-beta with cutoff agent that is using a silly evaluation function. See if you can defeat the agent in a few games. Describe (3-4 sentences) what your plan to defeat it every time. Explain briefly (2-3 sentences) why your plan works.
c. In the function c4 good eval, write a new evaluation function. Using this function, write code in problem 1c that will play an alpha-beta agent with depth cutoff 4 using your evaluation function against a random agent. Play once as X and once as O.(Note: For this problem and also 1(d) and also 2(b), it may help to write a version of your eval function to evaluate as X and another version of your eval function to evaluate as O. This is fine.) Have the function return a tuple (nx, no), where nx is the number of games that your agent wins as X, and no is the number of games that your agent wins as O. So if you win both games, you return (1,1).
Describe (2-3 sentences) your evaluation function in your writeup and explain (2-3 sentences) why you think it should do well. If your agent doesnt usually win against a random agent, then you probably did something wrong.
d. In the function problem 1d, run 8 games of an alpha-beta-cutoff agent using my evaluation function versus an alpha-beta-cutoff agent using your evaluation function, with each agent playing 4 times as X and 4 times as O. Run four of games at depth limit 2 for both agents, then four games at depth limit 3 for both agents. Return a tuple (nx, no), where nx is the number of games that your agent wins as X, and no is the number of games that your agent wins as O. So if you win all 8 games, you return (4,4).
sys.path.append('aima-python')
from games import *
import math
def c4_silly_eval(state):
'''Example of a silly evaluation function:
Each X piece is worth points based on its column number (1 through 6)
Each O piece is worth points based in its -column number
''!
ev =0
for col in range(1,7):
for row in range(1,8):
if state.board.get((row,col))=='X':
ev +=(col *0.01)
elif state.board.get((row, col))=='0':
ev -=(col *0.01)
return ev
def c4_good_eval(state):
'''Write your answer to 1c in this function!
''!
return 0
def ab_cutoff_player(game, state):
return alpha_beta_cutoff_search(state, game, d=2, eval_fn=c4_silly_eval)
class PS3:
def init(self):
pass
def problem_1a(self):
tt = TicTacToe()
tt.play_game(alpha_beta_player,query_player)
def problem_1b(self):
c4= ConnectFour()
c4.play_game(ab_cutoff_player, query_player)
def problem_1c(self):
write your code for problem 1c here
return 0,0
def problem_1d(self):
write your code for problem 1d here
return 0,0
def problem_2b(self):
write your code for problem 2d here
return 0,0
def main():
ps3= PS3()
An example for you to follow to get you started on Games
print('Example Problem, playing Tic Tac Toe:')
print('=====================================')
ps3.problem_1a()
print('Example Problem, playing Connect 4 against my silly eval:')
print('========================================================')
uncomment to get it to run problem2
#ps3.problem_1b()
if name == 'main':
main()
class Gomoku(TicTacToe):
"""Also known as Five in a row."""
def init(self, h=15, v=16, k=5):
TicTacToe.init(self, h, v, k)
complete the coding portions for 1 c , 1 d , 2 a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!