コード例 #1
0
ファイル: DecapawnBoard.cs プロジェクト: langeds/aima
        public ArrayList getSuccessorBoards(string whoMoves)
        {
            ArrayList retVal = new ArrayList();

            if (whoMoves.Equals(W))
            {
                ArrayList whitePieces = this.getPieces(W);
                foreach (XYLocation fromloc in whitePieces)
                {
                    ArrayList moves = this.getMoves(fromloc);
                    foreach (XYLocation toloc in moves)
                    {
                        DecapawnBoard board = this.cloneBoard();
                        board.movePiece(fromloc, toloc);
                        retVal.Add(board);
                    }
                }
            }
            else
            {
                ArrayList blackPieces = this.getPieces(B);
                foreach (XYLocation fromloc in blackPieces)
                {
                    ArrayList moves = this.getMoves(fromloc);
                    foreach (XYLocation toloc in moves)
                    {
                        DecapawnBoard board = this.cloneBoard();
                        board.movePiece(fromloc, toloc);
                        retVal.Add(board);
                    }
                }
            }
            return(retVal);
        }
コード例 #2
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
        public override GameState makeMove(GameState state, Object o)
        {
            GameState retVal = new GameState();
            //a move is the board itself
            DecapawnBoard move = ((DecapawnBoard)o).cloneBoard();

            //we need to:
            //find out whose move it is
            string playerToMove = getPlayerToMove(state);

            ArrayList newMoves;

            //set the player whose move is next
            if (playerToMove.Equals("W"))
            {
                retVal.put("player", "B");
                //add the new moves
                newMoves = move.getSuccessorBoards("B");
            }
            else
            {
                retVal.put("player", "W");
                //add the new moves
                newMoves = move.getSuccessorBoards("W");
            }

            int parentLevel = getLevel(state);

//			if (parentLevel <= this.MaxSearchDepth && this.computeUtilityCallsThisMove < this.MaxMovesToConsider)
//			{
            retVal.put("moves", newMoves);
            retVal.put("utility", computeUtility(move,
                                                 getPlayerToMove(getState())));
//			}
//			else
//			{
//				for (int i = 1; i < newMoves.Count; i++)
//				{
//					newMoves.RemoveAt(i);
//				}
//
//				retVal.put("moves",newMoves);
//				retVal.put("utility",0);
//			}
            retVal.put("board", move);

            retVal.put("level", parentLevel + 1);
            //if (newMoves.Count != 0)
            presentState = retVal;

            return(retVal);
        }
コード例 #3
0
ファイル: DecapawnBoard.cs プロジェクト: langeds/aima
        public Object clone()
        {
            DecapawnBoard newBoard = new DecapawnBoard();

            for (int i = 0; i < boardSize; i++)
            {
                for (int j = 0; j < boardSize; j++)
                {
                    String s = getValue(i, j);
                    newBoard.setValue(i, j, s);
                }
            }
            return(newBoard);
        }
コード例 #4
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
        public override bool terminalTest(GameState state)
        {
            DecapawnBoard board = (DecapawnBoard)state.get("board");
            //			bool line = board.lineThroughBoard();
            //			bool filled = board.getNumberOfMarkedPositions() == 9;
            //			return (line || filled);
            int  thisLevel = getLevel(state);
            bool bailOut   = false;

            if (thisLevel >= this.MaxSearchDepth && this.computeUtilityCallsThisMove > this.MaxMovesToConsider)
            {
                bailOut = true;
            }
            return(board.gameLost("B") || board.gameLost("W") || bailOut);
        }
コード例 #5
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
 private int computeUtilityBetter(DecapawnBoard aBoard, string playerToMove, int thisLevel)
 {
     //int thisLevel = getLevel(state);
     if (aBoard.gameLost("W"))
     {
         if (playerToMove.Equals("W"))
         {
             return(-100 / thisLevel);
         }
     }
     else if (aBoard.gameLost("B"))
     {
         if (playerToMove.Equals("B"))
         {
             return(100 / thisLevel);
         }
     }
     return(0);
 }
コード例 #6
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
        //get all possible successors from the current state
        public override ArrayList getSuccessorStates(GameState state)
        {
            GameState temp        = presentState;
            ArrayList retVal      = new ArrayList();
            int       parentLevel = getLevel(state);

            for (int i = 0; i < getMoves(state).Count; i++)
            {
                //XYLocation loc = (XYLocation) getMoves(state)[i];
                //for each move, actually make the move
                DecapawnBoard move = (DecapawnBoard)getMoves(state)[i];

                GameState aState = makeMove(state, move);
                aState.put("moveMade", move);
                aState.put("level", parentLevel + 1);
                retVal.Add(aState);
            }
            presentState = temp;
            return(retVal);
        }
コード例 #7
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
        private int computeUtility(DecapawnBoard aBoard, string playerToMove)
        {
            //int retVal = 0;
            if (aBoard.gameLost("W"))
            {
                if (playerToMove.Equals("W"))
                {
                    return(-1);
                }
            }
            else if (aBoard.gameLost("B"))
            {
                if (playerToMove.Equals("B"))
                {
                    return(1);
                }
            }

            return(0);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: langeds/aima
        private void btnAlphaBetaDecapawn_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text  = "ALPHA BETA Decapawn ";
            this.textBox1.Text += System.Environment.NewLine;
            Decapawn t4 = new Decapawn();

            while (!(t4.hasEnded()))
            {
                this.textBox1.Text += (System.Environment.NewLine + t4.getPlayerToMove(t4.getState())
                                       + "  playing ... ");

                t4.makeAlphaBetaMove();
                GameState     presentState = t4.getState();
                DecapawnBoard board        = t4.getBoard(presentState);
                this.textBox1.Text += System.Environment.NewLine;
                this.textBox1.Text += board.ToString();
                this.textBox1.Refresh();
                this.Refresh();
            }
            this.textBox1.Text += "ALPHA BETA Decapawn DEMO done";
        }
コード例 #9
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
		public Decapawn() 
		{
			ArrayList moves = new ArrayList();
			//first, add all possible moves from the initial state
			//assume white goes first
			//store moves as gameboards
			DecapawnBoard board = new DecapawnBoard();
			moves = board.getSuccessorBoards(FirstPlayer);

			//all the moves from the current state
			initialState.put("moves", moves);
			//the player whose move it is
			initialState.put("player", FirstPlayer);

			initialState.put("utility", 0);
			//the board
			initialState.put("board", board);
			//the number of moves that have been made so far
			initialState.put("level", 0);
			presentState = initialState;
		}
コード例 #10
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
        public Decapawn()
        {
            ArrayList moves = new ArrayList();
            //first, add all possible moves from the initial state
            //assume white goes first
            //store moves as gameboards
            DecapawnBoard board = new DecapawnBoard();

            moves = board.getSuccessorBoards(FirstPlayer);

            //all the moves from the current state
            initialState.put("moves", moves);
            //the player whose move it is
            initialState.put("player", FirstPlayer);

            initialState.put("utility", 0);
            //the board
            initialState.put("board", board);
            //the number of moves that have been made so far
            initialState.put("level", 0);
            presentState = initialState;
        }
コード例 #11
0
ファイル: DecapawnBoard.cs プロジェクト: langeds/aima
        public override bool Equals(Object anObj)
        {
            bool          retVal       = true;
            DecapawnBoard anotherBoard = (DecapawnBoard)anObj;
            bool          secondBreak  = false;

            for (int i = 0; i < boardSize; i++)
            {
                for (int j = 0; j < boardSize; j++)
                {
                    if (anotherBoard.getValue(i, j) != getValue(i, j))
                    {
                        retVal      = false;
                        secondBreak = true;
                        break;
                    }
                }
                if (secondBreak == false)
                {
                    break;
                }
            }
            return(retVal);
        }
コード例 #12
0
ファイル: DecapawnBoard.cs プロジェクト: langeds/aima
		public Object clone() 
		{
			DecapawnBoard newBoard = new DecapawnBoard();
			for (int i = 0; i < boardSize; i++) 
			{
				for (int j = 0; j < boardSize; j++) 
				{
					String s = getValue(i, j);
					newBoard.setValue(i, j, s);
				}
			}
			return newBoard;
		}
コード例 #13
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
		private int computeUtility(DecapawnBoard aBoard, string playerToMove) 
		{
			//int retVal = 0;
			if (aBoard.gameLost("W")) 
			{
				if (playerToMove.Equals("W"))
					return -1;
			}
			else if (aBoard.gameLost("B"))
			{
				if (playerToMove.Equals("B"))
					return 1;
			}

			return 0;
		}
コード例 #14
0
ファイル: Decapawn.cs プロジェクト: langeds/aima
		private int computeUtilityBetter(DecapawnBoard aBoard, string playerToMove,int thisLevel) 
		{
			//int thisLevel = getLevel(state);
			if (aBoard.gameLost("W")) 
			{
				if (playerToMove.Equals("W"))
					return -100/thisLevel;
			}
			else if (aBoard.gameLost("B"))
			{
				if (playerToMove.Equals("B"))
					return 100/thisLevel;
			}
			return 0;
		}