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
|
# 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
|
@staticmethod
|
||||||
def board_features_tesauro(board, cur_player):
|
def board_features_tesauro(board, cur_player):
|
||||||
features = []
|
def ordinary_trans(val, player):
|
||||||
for player in [-1,1]:
|
abs_val = val * player
|
||||||
sum = 0.0
|
if abs_val <= 0: return (0,0,0,0)
|
||||||
for board_range in range(1,25):
|
elif abs_val == 1: return (1,0,0,0)
|
||||||
pin = board[board_range]
|
elif abs_val == 2: return (1,1,0,0)
|
||||||
#print("PIIIN:",pin)
|
elif abs_val == 3: return (1,1,1,0)
|
||||||
feature = [0.0]*4
|
else: return (1,1,1, (abs_val - 3) / 2)
|
||||||
if np.sign(pin) == np.sign(player):
|
|
||||||
sum += abs(pin)
|
def bar_trans(board, player):
|
||||||
for i in range(min(abs(pin), 3)):
|
if player == 1: return (abs(board[0]/2),)
|
||||||
feature[i] = 1
|
elif player == -1: return (abs(board[25]/2),)
|
||||||
if (abs(pin) > 3):
|
|
||||||
feature[3] = (abs(pin)-3)/2
|
# def ordinary_trans_board(board, player):
|
||||||
features += feature
|
# return np.array(
|
||||||
#print("SUUUM:",sum)
|
# [ordinary_trans(x, player) for x in board[1:25]]
|
||||||
# Append the amount of men on the bar of the current player divided by 2
|
# ).flatten()
|
||||||
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
|
board_rep = []
|
||||||
features.append((15 - sum) / 15)
|
for player in [1,-1]:
|
||||||
features += ([1,0] if np.sign(cur_player) > 0 else [0,1])
|
for x in board[1:25]:
|
||||||
test = np.array(features).reshape(1,-1)
|
board_rep += ordinary_trans(x, player)
|
||||||
#print("TEST:",test)
|
board_rep += bar_trans(board, player)
|
||||||
return test
|
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