-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws2544.py
102 lines (75 loc) · 3.07 KB
/
ws2544.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
# -*- coding: utf-8 -*
"""
COMS W4701 Artificial Intelligence - Programming Homework 2
An AI player for Othello. This is the template file that you need to
complete and submit.
@author: YOUR NAME AND UNI
"""
import random
import sys
import time
# You can use the functions in othello_shared to write your AI
from othello_shared import find_lines, get_possible_moves, get_score, play_move
def compute_utility(board, color):
"""
Return the utility of the given board state
(represented as a tuple of tuples) from the perspective
of the player "color" (1 for dark, 2 for light)
"""
return 0
############ MINIMAX ###############################
def minimax_min_node(board, color):
return None
def minimax_max_node(board, color):
return None
def select_move_minimax(board, color):
"""
Given a board and a player color, decide on a move.
The return value is a tuple of integers (i,j), where
i is the column and j is the row on the board.
"""
return 0,0
############ ALPHA-BETA PRUNING #####################
#alphabeta_min_node(board, color, alpha, beta, level, limit)
def alphabeta_min_node(board, color, alpha, beta):
return None
#alphabeta_max_node(board, color, alpha, beta, level, limit)
def alphabeta_max_node(board, color, alpha, beta):
return None
def select_move_alphabeta(board, color):
return 0,0
####################################################
def run_ai():
"""
This function establishes communication with the game manager.
It first introduces itself and receives its color.
Then it repeatedly receives the current score and current board state
until the game is over.
"""
print("Minimax AI") # First line is the name of this AI
color = int(input()) # Then we read the color: 1 for dark (goes first),
# 2 for light.
while True: # This is the main loop
# Read in the current game status, for example:
# "SCORE 2 2" or "FINAL 33 31" if the game is over.
# The first number is the score for player 1 (dark), the second for player 2 (light)
next_input = input()
status, dark_score_s, light_score_s = next_input.strip().split()
dark_score = int(dark_score_s)
light_score = int(light_score_s)
if status == "FINAL": # Game is over.
print
else:
board = eval(input()) # Read in the input and turn it into a Python
# object. The format is a list of rows. The
# squares in each row are represented by
# 0 : empty square
# 1 : dark disk (player 1)
# 2 : light disk (player 2)
# Select the move and send it to the manager
movei, movej = select_move_minimax(board, color)
#movei, movej = select_move_alphabeta(board, color)
print("{} {}".format(movei, movej))
if __name__ == "__main__":
run_ai()