예제 #1
0
 public Node(Move move, Node parent, State state)
 {
     this.random = new Random();
     this.state = state;
     this.generatingMove = move;
     this.parent = parent;
     this.results = 0;
     this.visits = 0;
     this.children = new List<Node>();
     this.untriedMoves = state.GetMoves();
 }
예제 #2
0
 // adds a child node to the list of children
 // after exploring a move - removes the move from untried
 public Node AddChild(Move move, State state)
 {
     Node child = new Node(move, this, state);
     this.untriedMoves.Remove(move);
     this.children.Add(child);
     return child;
 }
예제 #3
0
        // Applies the move to this state and returns the resulting state
        public State ApplyMove(Move move)
        {
            if (move is PlayerMove)
            {
                int[][] clonedBoard = BoardHelper.CloneBoard(this.board);
                if (((PlayerMove)move).Direction == DIRECTION.LEFT)
                {
                    State state = ApplyLeft(clonedBoard);
                    state.GeneratingMove = move;
                    return state;
                }
                else if (((PlayerMove)move).Direction == DIRECTION.RIGHT)
                {
                    State state = ApplyRight(clonedBoard);
                    state.GeneratingMove = move;
                    return state;
                }

                else if (((PlayerMove)move).Direction == DIRECTION.DOWN)
                {
                    State state = ApplyDown(clonedBoard);
                    state.GeneratingMove = move;
                    return state;
                }
                else if (((PlayerMove)move).Direction == DIRECTION.UP)
                {
                    State state = ApplyUp(clonedBoard);
                    state.GeneratingMove = move;
                    return state;
                }
                else throw new Exception();
            }
            else if (move is ComputerMove)
            {
                State result = new State(BoardHelper.CloneBoard(this.board), points, GameEngine.PLAYER);
                int xPosition = ((ComputerMove)move).Position.Item1;
                int yPosition = ((ComputerMove)move).Position.Item2;
                int tileValue = ((ComputerMove)move).Tile;
                result.Board[xPosition][yPosition] = tileValue;
                result.GeneratingMove = move;
                return result;
            }
            else
            {
                throw new Exception();
            }
        }