hi There,
i have made an AI player for the game Oware, i am looking to improve my programming in order to make my player stronger. can anyone help?
here is my code
import random
#pots = [[1,2,8,4,2,6], [4,4,4,4,3,4]]
def ai_player(pots, scoring_pits, turn, valid_moves):
"""
Input:
pots: list of pot values for each player, e.g:
[[4, 4, 4, 4, 4, 4], <-- always current player
[4, 4, 4, 4, 4, 4]] <-- always opponent
scoring_pits: list of scoring pit values - [0, 0]
turn: integer turn counter (starts from 1)
valid_moves: list of valid moves (indexes), e.g:
[0, 1, 2, 3, 4, 5]
Return:
pot index --> 0 to 5
--> pot value can't be zero
--> must be an integer object
"""
points = [0,0,0,0,0,0]
opp_1 = pots[1][0]
opp_2 = pots[1][1]
opp_3 = pots[1][2]
opp_4 = pots[1][3]
opp_5 = pots[1][4]
opp_6 = pots[1][5]
if 1<= opp_1 <= 2:
points[0] = points[0] + 1
if 1<= opp_2 <= 2:
points[1] = points[1] + 1
if points[0] != 0:
points[1] = points[1] + 1
if 1<= opp_3 <= 2:
points[2] = points[2] + 1
if points[1] != 0:
points[2] = points[2] +1
if points[0] != 0:
points[2] = points[2] +1
if 1<= opp_4 <= 2:
points[3] = points[3] + 1
if points[2] != 0:
points[3] = points[3] +1
if points[1] != 0:
points[3] = points[3] +1
if points[0] != 0:
points[3] = points[3] +1
if 1<= opp_5 <= 2:
points[4] = points[4] + 1
if points[3] != 0:
points[4] = points[4] +1
if points[2] != 0:
points[4] = points[4] +1
if points[1] != 0:
points[4] = points[4] +1
if points[0] != 0:
points[4] = points[4] +1
if 1<= opp_6 <= 2:
points[5] = points[5] + 1
if points[4] != 0:
points[5] = points[5] +1
if points[3] != 0:
points[5] = points[5] +1
if points[2] != 0:
points[5] = points[5] +1
if points[1] != 0:
points[5] = points[5] +1
if points[0] != 0:
points[5] = points[5] +1
play_max = 0
max_points = max(points)
if max_points != 0:
for i in range(5):
if points[i] == max_points:
position_max = i
play_max = position_max + 1
#print position_max, "pos"
#print points, "points"
#print max_points , "max"
#print play_max, "play_max"
ours = [0,0,0,0,0,0]
ours[5] = pots[0][0]
ours[4] = pots[0][1]
ours[3] = pots[0][2]
ours[2] = pots[0][3]
ours[1] = pots[0][4]
ours[0] = pots[0][5]
#print ours
for p in range (5):
if ours[p] == play_max + p:
n = len(valid_moves)
for z in range(n):
if p == valid_moves[z]:
ind = p
return ind
else:
ind = random.choice(valid_moves)
return ind
#miooprint ind, "ind"
#print pots
"""
def_points = [0,0,0,0,0,0]
if 1<= ours[5] <=2:
def_points[5] = def_points[5] + 2
if 1<= ours[4] <=2:
def_points[4] = def_points[4] + 2
if def_points[4] == 2:
def_points[5] += 1
if 1<= ours[3] <=2:
def_points[3] = def_points[4] + 1
if def_points[3] == 2:
def_points[4] += 1
if def_points[5] == 2:
def_points[5] += 1
if 1<= ours[2] <=2:
def_points[2] = def_points[2] + 1
if def_points[2] == 2:
def_points[3] += 1
if def_points[4] == 2:
def_points[4] += 1
if 1<= ours[1] <=2:
def_points[1] = def_points[1] + 1
if def_points[1] == 2:
def_points[2] += 1
if def_points[3] == 2:
def_points[3] += 1
if 1<= ours[0] <=2:
def_points[0] = def_points[0] + 1
if def_points[0] == 2:
def_points[1] += 1
if def_points[2] == 2:
def_points[2] += 1
#print def_points
m = len(valid_moves)
def_move = max(def_points)
if def_move != 0:
for c in range(5):
if pots[0][c] == def_move:
for z in range(m):
if c == valid_moves[z]:
ind = int(c)
return ind
"""
"""
else:
ind = random.choice(valid_moves)
return ind
"""