示例#1
0
        private int computeUtility(HexapawnBoard aBoard, string playerToMove)
        {
            //int retVal = 0;
//			if (aBoard.gameLost("W"))
//			{
//				if (playerToMove.Equals("W"))
//					return -1;
//			}
//			else if (aBoard.gameLost("B"))
//			{
//				if (playerToMove.Equals("W"))
//					return 1;
//			}
            if (aBoard.gameLost("W"))
            {
                if (playerToMove.Equals("W"))
                {
                    return(-1);
                }
            }
            else if (aBoard.gameLost("B"))
            {
                if (playerToMove.Equals("B"))
                {
                    return(1);
                }
            }
            return(0);
        }
示例#2
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)
                    {
                        HexapawnBoard 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)
                    {
                        HexapawnBoard board = this.cloneBoard();
                        board.movePiece(fromloc, toloc);
                        retVal.Add(board);
                    }
                }
            }
            return(retVal);
        }
示例#3
0
        public override bool terminalTest(GameState state)
        {
            HexapawnBoard board = (HexapawnBoard)state.get("board");

//			bool line = board.lineThroughBoard();
//			bool filled = board.getNumberOfMarkedPositions() == 9;
//			return (line || filled);
            return(board.gameLost("B") || board.gameLost("W"));
        }
示例#4
0
        public Object clone()
        {
            HexapawnBoard newBoard = new HexapawnBoard();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    String s = getValue(i, j);
                    newBoard.setValue(i, j, s);
                }
            }
            return(newBoard);
        }
示例#5
0
文件: Form1.cs 项目: langeds/aima
        private void btnHexAlphaBeta_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text  = "ALPHA BETA Hexapawn";
            this.textBox1.Text += System.Environment.NewLine;
            Hexapawn t4 = new Hexapawn();

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

                t4.makeAlphaBetaMove();
                GameState     presentState = t4.getState();
                HexapawnBoard board        = t4.getBoard(presentState);
                this.textBox1.Text += System.Environment.NewLine;
                this.textBox1.Text += board.ToString();
            }
            this.textBox1.Text += "ALPHA BETA Hexapawn DEMO done";
        }
示例#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
                HexapawnBoard move = (HexapawnBoard)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
文件: Hexapawn.cs 项目: langeds/aima
		public Hexapawn() 
		{
			ArrayList moves = new ArrayList();
			//first, add all possible moves from the initial state
			//assume white goes first
			//store moves as gameboards
			HexapawnBoard board = new HexapawnBoard();
			moves = board.getSuccessorBoards("W");

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

			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;
		}
示例#8
0
文件: Form1.cs 项目: langeds/aima
        private void btnHexMiniMax_Click(object sender, System.EventArgs e)
        {
            this.textBox1.Text  = "MINI MAX Hexapawn";
            this.textBox1.Text += System.Environment.NewLine;

            Hexapawn t3 = new Hexapawn();

            while (!(t3.hasEnded()))
            {
                this.textBox1.Text += (System.Environment.NewLine + t3.getPlayerToMove(t3.getState()) + " playing");
                this.textBox1.Text += System.Environment.NewLine;
                t3.makeMiniMaxMove();
                GameState     presentState = t3.getState();
                HexapawnBoard board        = t3.getBoard(presentState);
                this.textBox1.Text += System.Environment.NewLine;
                this.textBox1.Text += board.ToString();
                this.textBox1.Refresh();
                this.Refresh();
            }
            this.textBox1.Text += "Mini MAX Hexapawn DEMO done";
        }
示例#9
0
        public Hexapawn()
        {
            ArrayList moves = new ArrayList();
            //first, add all possible moves from the initial state
            //assume white goes first
            //store moves as gameboards
            HexapawnBoard board = new HexapawnBoard();

            moves = board.getSuccessorBoards("W");

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

            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
        public override GameState makeMove(GameState state, Object o)
        {
            GameState retVal = new GameState();
            //a move is the board itself
            HexapawnBoard move = ((HexapawnBoard)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");
            }

            retVal.put("moves", newMoves);
            retVal.put("board", move);
            retVal.put("utility", computeUtility(move,
                                                 getPlayerToMove(getState())));
            retVal.put("level", getLevel(state) + 1);
            //if (newMoves.Count != 0)
            presentState = retVal;

            return(retVal);
        }
示例#11
0
        public override bool Equals(Object anObj)
        {
            bool          retVal       = true;
            HexapawnBoard anotherBoard = (HexapawnBoard)anObj;
            bool          secondBreak  = false;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if (anotherBoard.getValue(i, j) != getValue(i, j))
                    {
                        retVal      = false;
                        secondBreak = true;
                        break;
                    }
                }
                if (secondBreak == false)
                {
                    break;
                }
            }
            return(retVal);
        }
示例#12
0
文件: Hexapawn.cs 项目: langeds/aima
		private int computeUtility(HexapawnBoard aBoard, string playerToMove) 
		{
			//int retVal = 0;
//			if (aBoard.gameLost("W")) 
//			{
//				if (playerToMove.Equals("W"))
//					return -1;
//			}
//			else if (aBoard.gameLost("B"))
//			{
//				if (playerToMove.Equals("W"))
//					return 1;
//			}
			if (aBoard.gameLost("W")) 
			{
				if (playerToMove.Equals("W"))
					return -1;
			}
			else if (aBoard.gameLost("B"))
			{
				if (playerToMove.Equals("B"))
					return 1;
			}
			return 0;
		}
示例#13
0
		public Object clone() 
		{
			HexapawnBoard newBoard = new HexapawnBoard();
			for (int i = 0; i < 3; i++) 
			{
				for (int j = 0; j < 3; j++) 
				{
					String s = getValue(i, j);
					newBoard.setValue(i, j, s);
				}
			}
			return newBoard;
		}