예제 #1
0
        public override bool terminalTest(GameState state)
        {
            TicTacToeBoard board  = (TicTacToeBoard)state.get("board");
            bool           line   = board.lineThroughBoard();
            bool           filled = board.getNumberOfMarkedPositions() == 9;

            return(line || filled);
        }
예제 #2
0
        public Object clone()
        {
            TicTacToeBoard newBoard = new TicTacToeBoard();

            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);
        }
예제 #3
0
        private int computeUtility(TicTacToeBoard aBoard, string playerToMove)
        {
            int retVal = 0;

            if (aBoard.lineThroughBoard())
            {
                if (playerToMove.Equals("X"))
                {
                    retVal = -1;
                }
                else
                {
                    retVal = 1;
                }
            }
            return(retVal);
        }
예제 #4
0
        public GameState getMove(GameState state, int x, int y)
        {
            GameState  retVal   = null;
            XYLocation loc      = new XYLocation(x, y);
            ArrayList  moves    = getMoves(state);
            ArrayList  newMoves = (ArrayList)moves.Clone();

            if (moves.Contains(loc))
            {
                //int index = newMoves.indexOf(loc);
                int index = newMoves.IndexOf(loc);
                //newMoves.Remove(index);
                //.remove function is not overloaded in .net like it is in java
                //in .NET .remove only removes the instance of the parameter,
                //not the object at the index
                newMoves.RemoveAt(index);

                retVal = new GameState();

                retVal.put("moves", newMoves);
                TicTacToeBoard newBoard = getBoard(state).cloneBoard();
                if (getPlayerToMove(state) == "X")
                {
                    newBoard.markX(x, y);
                    retVal.put("player", "O");
                }
                else
                {
                    newBoard.markO(x, y);
                    retVal.put("player", "X");
                }
                retVal.put("board", newBoard);
                retVal.put("utility", computeUtility(newBoard,
                                                     getPlayerToMove(getState())));
                retVal.put("level", getLevel(state) + 1);
                //presentState = retVal;
            }
            return(retVal);
        }
예제 #5
0
        public override bool Equals(Object anObj)
        {
            bool           retVal       = true;
            TicTacToeBoard anotherBoard = (TicTacToeBoard)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);
        }
예제 #6
0
파일: TicTacToe.cs 프로젝트: langeds/aima
		private int computeUtility(TicTacToeBoard aBoard, string playerToMove) 
		{
			int retVal = 0;
			if (aBoard.lineThroughBoard()) 
			{
				if (playerToMove.Equals("X")) 
				{
					retVal = -1;
				} 
				else 
				{
					retVal = 1;
				}

			}
			return retVal;
		}
예제 #7
0
		public Object clone() 
		{
			TicTacToeBoard newBoard = new TicTacToeBoard();
			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;
		}