def ttentry(self): """ Returns game entry """ entry = [self.hands[i][j] for i in range(self.numplayers) for j in range(self.numhands)] entry = entry + [self.nplayer] return tuple(entry) def back_to_startstate(self, move): """ Checking if move will cause returning to start state - never-ending loop protection """ nextstate = self.copy() nextstate.make_move(move) hands_min = min([min(nextstate.hands[i]) for i in range(self.numplayers)]) hands_max = max([max(nextstate.hands[i]) for i in range(self.numplayers)]) return hands_min == 1 and hands_max == 1 if __name__ == "__main__": from easyAI import Negamax, AI_Player, SSS, DUAL from easyAI.AI.TT import TT ai_algo_neg = Negamax(4) ai_algo_sss = SSS(4) dict_tt = DictTT(32, JSWHashTT()) ai_algo_dual = DUAL(4, tt=TT(dict_tt)) Chopsticks( [AI_Player(ai_algo_neg),AI_Player(ai_algo_dual)]).play() #first player never wins print '-'*10 print 'Statistics of custom dictionary:' print 'Calls of hash: ', dict_tt.num_calls print 'Collisions: ', dict_tt.num_collisions
def init(self, width): # called at start of game self.start = True self.width = width self.ai_algo = DUAL(2) self.ttt = GomokuGame( [Human_Player(), AI_Player(self.ai_algo)], width, 2)
#==================================== PARAMETERS ========================================= timeNo = 20 # the no of times the test should run player1Win = 0 pl1No = "negamax" pl2No = "rlAgent" pl1Steps = 4 # the number of steps each algo thinks in advanced pl2Steps = 4 rlAgent = RLAgent('./models/mix3/train_49500.h5') aiAlgosPl1 = { "negamax": Negamax(pl1Steps), "dual": DUAL(pl1Steps), "sss": SSS(pl1Steps), "negamaxRand": NegamaxRand(pl1Steps), "rlAgent": rlAgent } aiAlgosPl2 = { "negamax": Negamax(pl2Steps), "dual": DUAL(pl2Steps), "sss": SSS(pl2Steps), "negamaxRand": NegamaxRand(pl2Steps), "rlAgent": rlAgent } resultList = [] strategy = Strategy.NORMAL # scoring method strategyVal = strategy.value
{{ttt.spot_string(j, i)}} </button> </td> {% endfor %} </tr> {% endfor %} </table> <button type="submit" name="reset">Start Over</button> </form> </body> </html> ''' app = Flask(__name__) # ai_algo = Negamax(2 ) ai_algo = DUAL(2, win_score=1000000) width = 15 def pack(arr): ret = {} for x in xrange(0, width): for y in xrange(0, width): if arr[x][y] != 0: ret[(x, y)] = arr[x][y] return ret def unpack(dict): arr = np.zeros((width, width), np.int8) for x, y in dict:
def create_dual_tt(depth): ai_algo_dual = DUAL(depth, tt=TT()) return create_benchmark_game(ai_algo_dual)
def create_dual(depth): ai_algo_dual = DUAL(depth) return create_benchmark_game(ai_algo_dual)
for j in range(self.numhands) ] entry = entry + [self.nplayer] return tuple(entry) def back_to_startstate(self, move): """ Checking if move will cause returning to start state - never-ending loop protection """ nextstate = self.copy() nextstate.make_move(move) hands_min = min( [min(nextstate.hands[i]) for i in range(self.numplayers)]) hands_max = max( [max(nextstate.hands[i]) for i in range(self.numplayers)]) return hands_min == 1 and hands_max == 1 if __name__ == "__main__": from easyAI import Negamax, AI_Player, SSS, DUAL, MTDbi, MTDf, MTDstep from easyAI.AI.TT import TT dict_tt = DictTT(32) ai_algo_sss = SSS(6, tt=TT(dict_tt)) # SSS algorithm ai_algo_neg = Negamax(6, tt=TT(dict_tt)) # Negamax algorithm ai_algo_bi = MTDbi(6, tt=TT(dict_tt)) # MTDbi algorithm ai_algo_f = MTDf(5, tt=TT(dict_tt)) # MTDf algorithm ai_algo_step = MTDstep(5, tt=TT(dict_tt)) # MTDstep algorithm ai_algo_dual = DUAL(4, tt=TT(dict_tt)) # DUAL algorithm Chopsticks([AI_Player(ai_algo_neg), AI_Player(ai_algo_step)]).play() dict_tt.print_stats()