From cc1e01084098404092f7cc7b2eccd9ee5c456ad8 Mon Sep 17 00:00:00 2001 From: Pownie Date: Sun, 15 Apr 2018 23:51:28 +0200 Subject: [PATCH] Uses proper board instead of Alex' drunken mistakes --- board.py | 108 +++++++++++++++++++++++++++---------------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/board.py b/board.py index 0186e81..73d2095 100644 --- a/board.py +++ b/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