Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        //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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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";
        }
Esempio n. 9
0
		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;
		}
Esempio n. 10
0
        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;
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
		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;
		}
Esempio n. 13
0
		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;
		}
Esempio n. 14
0
		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;
		}