Uses proper board instead of Alex' drunken mistakes
This commit is contained in:
parent
f59fe27e5f
commit
cc1e010840
108
board.py
108
board.py
|
@ -55,62 +55,62 @@ class Board:
|
|||
|
||||
|
||||
# tesauro
|
||||
# @staticmethod
|
||||
# def board_features_tesauro(board, cur_player):
|
||||
# def ordinary_trans(val, player):
|
||||
# abs_val = val * player
|
||||
# if abs_val <= 0: return (0,0,0,0)
|
||||
# elif abs_val == 1: return (1,0,0,0)
|
||||
# elif abs_val == 2: return (1,1,0,0)
|
||||
# elif abs_val == 3: return (1,1,1,0)
|
||||
# else: return (1,1,1, (abs_val - 3) / 2)
|
||||
|
||||
# def bar_trans(board, player):
|
||||
# if player == 1: return (abs(board[0]/2),)
|
||||
# elif player == -1: return (abs(board[25]/2),)
|
||||
|
||||
# # def ordinary_trans_board(board, player):
|
||||
# # return np.array(
|
||||
# # [ordinary_trans(x, player) for x in board[1:25]]
|
||||
# # ).flatten()
|
||||
|
||||
# board_rep = []
|
||||
# for player in [1,-1]:
|
||||
# for x in board[1:25]:
|
||||
# board_rep += ordinary_trans(x, player)
|
||||
# board_rep += bar_trans(board, player)
|
||||
# board_rep += (15 - Board.num_of_checkers_for_player(board, player),)
|
||||
|
||||
# board_rep += ([1,0] if cur_player == 1 else [1,0])
|
||||
|
||||
# return np.array(board_rep).reshape(1,198)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def board_features_tesauro(board, cur_player):
|
||||
features = []
|
||||
for player in [-1,1]:
|
||||
sum = 0.0
|
||||
for board_range in range(1,25):
|
||||
pin = board[board_range]
|
||||
#print("PIIIN:",pin)
|
||||
feature = [0.0]*4
|
||||
if np.sign(pin) == np.sign(player):
|
||||
sum += abs(pin)
|
||||
for i in range(min(abs(pin), 3)):
|
||||
feature[i] = 1
|
||||
if (abs(pin) > 3):
|
||||
feature[3] = (abs(pin)-3)/2
|
||||
features += feature
|
||||
#print("SUUUM:",sum)
|
||||
# Append the amount of men on the bar of the current player divided by 2
|
||||
features.append((board[0] if np.sign(player) < 0 else board[25]) / 2.0)
|
||||
# Calculate how many pieces there must be in the home state and divide it by 15
|
||||
features.append((15 - sum) / 15)
|
||||
features += ([1,0] if np.sign(cur_player) > 0 else [0,1])
|
||||
test = np.array(features).reshape(1,-1)
|
||||
#print("TEST:",test)
|
||||
return test
|
||||
def ordinary_trans(val, player):
|
||||
abs_val = val * player
|
||||
if abs_val <= 0: return (0,0,0,0)
|
||||
elif abs_val == 1: return (1,0,0,0)
|
||||
elif abs_val == 2: return (1,1,0,0)
|
||||
elif abs_val == 3: return (1,1,1,0)
|
||||
else: return (1,1,1, (abs_val - 3) / 2)
|
||||
|
||||
def bar_trans(board, player):
|
||||
if player == 1: return (abs(board[0]/2),)
|
||||
elif player == -1: return (abs(board[25]/2),)
|
||||
|
||||
# def ordinary_trans_board(board, player):
|
||||
# return np.array(
|
||||
# [ordinary_trans(x, player) for x in board[1:25]]
|
||||
# ).flatten()
|
||||
|
||||
board_rep = []
|
||||
for player in [1,-1]:
|
||||
for x in board[1:25]:
|
||||
board_rep += ordinary_trans(x, player)
|
||||
board_rep += bar_trans(board, player)
|
||||
board_rep += (15 - Board.num_of_checkers_for_player(board, player),)
|
||||
|
||||
board_rep += ([1,0] if cur_player == 1 else [1,0])
|
||||
|
||||
return np.array(board_rep).reshape(1,198)
|
||||
|
||||
|
||||
# @staticmethod
|
||||
# def board_features_tesauro(board, cur_player):
|
||||
# features = []
|
||||
# for player in [-1,1]:
|
||||
# sum = 0.0
|
||||
# for board_range in range(1,25):
|
||||
# pin = board[board_range]
|
||||
# #print("PIIIN:",pin)
|
||||
# feature = [0.0]*4
|
||||
# if np.sign(pin) == np.sign(player):
|
||||
# sum += abs(pin)
|
||||
# for i in range(min(abs(pin), 3)):
|
||||
# feature[i] = 1
|
||||
# if (abs(pin) > 3):
|
||||
# feature[3] = (abs(pin)-3)/2
|
||||
# features += feature
|
||||
# #print("SUUUM:",sum)
|
||||
# # Append the amount of men on the bar of the current player divided by 2
|
||||
# features.append((board[0] if np.sign(player) < 0 else board[25]) / 2.0)
|
||||
# # Calculate how many pieces there must be in the home state and divide it by 15
|
||||
# features.append((15 - sum) / 15)
|
||||
# features += ([1,0] if np.sign(cur_player) > 0 else [0,1])
|
||||
# test = np.array(features).reshape(1,-1)
|
||||
# #print("TEST:",test)
|
||||
# return test
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user