def check(self, board, player): b = board.getBoard() ret = 0 #vertical check for c in range(len(b)): for r in range(len(b[c]) - 2): if (b[c][r] == player): if (b[c][r + 1] == player): if (b[c][r + 2] == player): ret = ret + 1 else: continue else: continue else: continue #horizontal check for c in range(len(b) - 2): for r in range(len(b[c])): if (b[c][r] == player): if (b[c + 1][r] == player): if (b[c + 2][r] == player): ret = ret + 1 else: continue else: continue else: continue #left to right, bottom to top / diagonal check for c in range(len(b) - 2): for r in range(len(b) - 3): if (b[c][r] == player): if (b[c + 1][r + 1] == player): if (b[c + 2][r + 2] == player): ret = ret + 1 else: continue else: continue else: continue #left to right, top to bottom \ diagonal check for c in range(len(b) - 1, 1, -1): for r in range(len(b[c]) - 2): if (b[c][r] == player): if (b[c - 1][r + 1] == player): if (b[c - 2][r + 2] == player): ret = ret + 1 else: continue else: continue else: continue return ret
def checkfirstmoves(self, board, player): b = board.getBoard() ret = 0 if b[3][0] == player: ret = ret + .2 if b[2][0] != ((-1) * player): ret = ret + .05 if b[4][0] != ((-1) * player): ret = ret + .05 return ret