示例#1
0
def test_whenNewMoveIsInFinishedBoardThenExceptionRaised():
    finished_board = SubBoard().add_my_move(SubBoardCoords(0, 0))\
                        .add_my_move(SubBoardCoords(0, 1))\
                        .add_my_move(SubBoardCoords(0, 2))

    with pytest.raises(MoveInFinishedBoardError):
        finished_board.add_my_move(SubBoardCoords(1, 1))
示例#2
0
文件: mcts.py 项目: LisaJD/Internship
 def CreateChildren(self):
     print(SubBoard)
     print(SubBoard.get_playable_coords(SubBoard))
     legal_moves = list(self.board_state.get_playable_coords())
     print(legal_moves)
     for move in legal_moves:
         self.children.append(Node(SubBoard.add_my_move(move)))
示例#3
0
 def winnableBy(self, subBoard: SubBoard):
     #print(subBoard)
     playable = subBoard.get_playable_coords()
     for x in range(0, len(subBoard.get_playable_coords())):
         tmpBoard = subBoard.add_opponent_move(
             SubBoardCoords(playable[x].row, playable[x].col))
         if tmpBoard.is_finished:
             if tmpBoard.winner == Player.ME or tmpBoard.winner == Player.OPPONENT:
                 #print(tmpBoard.winner)
                 return tmpBoard.winner
     for x in range(0, len(subBoard.get_playable_coords())):
         tmpBoard = subBoard.add_my_move(
             SubBoardCoords(playable[x].row, playable[x].col))
         if tmpBoard.is_finished:
             if tmpBoard.winner == Player.ME or tmpBoard.winner == Player.OPPONENT:
                 #print(tmpBoard.winner)
                 return tmpBoard.winner
     return 0
示例#4
0
    def subBoardHeuristic(self, sub_board: SubBoard, coords):
        count = 0

        tmpBoardMe = sub_board.add_my_move(coords)

        #if the move wins me the small board -> +1
        if tmpBoardMe.is_finished:
            if tmpBoardMe.winner == Player.ME:
                count += 1

        #if board is won by other player -1
        if tmpBoardMe.is_finished and tmpBoardMe.winner == Player.OPPONENT:
            count -= 1

            #if the current board can be won by them
            #if tmpBoardMe.is_finished and self.winnableBy(tmpBoardMe) == Player.OPPONENT:
            count -= 1

        #board where they will get sent is winnable by them -1
        if self.winnableBy(
                self.main_board.get_sub_board(
                    MainBoardCoords(coords.row,
                                    coords.col))) == Player.OPPONENT:
            count -= 1

        #board where they will get sent is winable by me
        if self.winnableBy(
                self.main_board.get_sub_board(
                    MainBoardCoords(coords.row, coords.col))) == Player.ME:
            count += 1

        #blocking the other player from wimnning
        tmpBoardOp = sub_board.add_opponent_move(coords)
        if tmpBoardOp.is_finished and tmpBoardOp.winner == Player.OPPONENT:
            count += 1

        return count