Esempio n. 1
0
 public void removeQueenFrom(XYLocation l)
 {
     if (squares[l.getXCoOrdinate()][l.getYCoOrdinate()] == 1)
     {
         squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 0;
     }
 }
Esempio n. 2
0
 public void removeQueenFrom(XYLocation l)
 {
     if (board[l.getXCoOrdinate(), l.getYCoOrdinate()] == 1)
     {
         board[l.getXCoOrdinate(), l.getYCoOrdinate()] = 0;
     }
 }
Esempio n. 3
0
        public void testXYLocationAtributeSettingOnConstruction()
        {
            XYLocation loc = new XYLocation(3, 4);

            Assert.AreEqual(3, loc.getXCoOrdinate());
            Assert.AreEqual(4, loc.getYCoOrdinate());
        }
Esempio n. 4
0
 public void addQueenAt(XYLocation l)
 {
     if (!(queenExistsAt(l)))
     {
         board[l.getXCoOrdinate(), l.getYCoOrdinate()] = 1;
     }
 }
Esempio n. 5
0
        public void mark(XYLocation loc, string symbol)
        {
            string[] _whichRow = null;
            _whichRow = whichRow(loc.getYCoOrdinate());

            _whichRow[loc.getXCoOrdinate()] = symbol;
        }
Esempio n. 6
0
 public void addQueenAt(XYLocation l)
 {
     if (!(queenExistsAt(l)))
     {
         squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 1;
     }
 }
Esempio n. 7
0
        public static int calculateSquareOfDistanceBetweenLocations(
            XYLocation loc1, XYLocation loc2)
        {
            int xdifference = loc1.getXCoOrdinate() - loc2.getXCoOrdinate();
            int ydifference = loc1.getYCoOrdinate() - loc2.getYCoOrdinate();

            return((xdifference * xdifference) + (ydifference * ydifference));
        }
Esempio n. 8
0
 /**
  * Moves the queen in the specified column (x-value of <code>l</code>) to
  * the specified row (y-value of <code>l</code>). The action assumes a
  * complete-state formulation of the n-queens problem.
  *
  * @param l
  */
 public void moveQueenTo(XYLocation l)
 {
     for (int i = 0; i < size; i++)
     {
         squares[l.getXCoOrdinate()][i] = 0;
     }
     squares[l.getXCoOrdinate()][l.getYCoOrdinate()] = 1;
 }
Esempio n. 9
0
        public bool isSquareUnderAttack(XYLocation l)
        {
            int x = l.getXCoOrdinate();
            int y = l.getYCoOrdinate();

            return(isSquareHorizontallyAttacked(x, y) ||
                   isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked(
                       x, y));
        }
Esempio n. 10
0
        public int getNumberOfAttacksOn(XYLocation l)
        {
            int x = l.getXCoOrdinate();
            int y = l.getYCoOrdinate();

            return(numberOfHorizontalAttacksOn(x, y)
                   + numberOfVerticalAttacksOn(x, y)
                   + numberOfDiagonalAttacksOn(x, y));
        }
        public void setBoard(List <XYLocation> locs)
        {
            int count = 0;

            for (int i = 0; i < locs.Capacity; i++)
            {
                XYLocation loc = locs[i];
                this.setValue(loc.getXCoOrdinate(), loc.getYCoOrdinate(), count);
                count = count + 1;
            }
        }
Esempio n. 12
0
        public void setBoard(ArrayList locs)
        {
            int count = 0;

            for (int i = 0; i < locs.Count; i++)
            {
                XYLocation loc = (XYLocation)locs[i];
                this.setValue(loc.getXCoOrdinate(), loc.getYCoOrdinate(), count);
                count = count + 1;
            }
        }
Esempio n. 13
0
        //
        // PRIVATE METHODS
        //
        private bool withinRadius(int radius, XYLocation agentLocation,
                                  XYLocation objectLocation)
        {
            int xdifference = agentLocation.getXCoOrdinate()
                              - objectLocation.getXCoOrdinate();
            int ydifference = agentLocation.getYCoOrdinate()
                              - objectLocation.getYCoOrdinate();

            return(Math.sqrt((xdifference * xdifference)
                             + (ydifference * ydifference)) <= radius);
        }
Esempio n. 14
0
        public void printPossibleMoves()
        {
            System.Console.WriteLine("Possible moves");

            List moves = getMoves(presentState);

            for (int i = 0; i < moves.Count; i++)
            {
                XYLocation moveLoc  = (XYLocation)moves.get(i);
                GameState  newState = getMove(presentState,
                                              moveLoc.getXCoOrdinate(), moveLoc.getYCoOrdinate());
                TicTacToeBoard board = (TicTacToeBoard)newState.get("board");
                System.Console.WriteLine("utility = " + computeUtility(newState));
                System.Console.WriteLine("");
            }
        }
Esempio n. 15
0
        public int evaluateManhattanDistanceOf(int i, XYLocation loc)
        {
            int retVal = -1;
            int xpos   = loc.getXCoOrdinate();
            int ypos   = loc.getYCoOrdinate();

            switch (i)
            {
            case 1:
                retVal = Math.Abs(xpos - 0) + Math.Abs(ypos - 1);
                break;

            case 2:
                retVal = Math.Abs(xpos - 0) + Math.Abs(ypos - 2);
                break;

            case 3:
                retVal = Math.Abs(xpos - 1) + Math.Abs(ypos - 0);
                break;

            case 4:
                retVal = Math.Abs(xpos - 1) + Math.Abs(ypos - 1);
                break;

            case 5:
                retVal = Math.Abs(xpos - 1) + Math.Abs(ypos - 2);
                break;

            case 6:
                retVal = Math.Abs(xpos - 2) + Math.Abs(ypos - 0);
                break;

            case 7:
                retVal = Math.Abs(xpos - 2) + Math.Abs(ypos - 1);
                break;

            case 8:
                retVal = Math.Abs(xpos - 2) + Math.Abs(ypos - 2);
                break;
            }
            return(retVal);
        }
Esempio n. 16
0
        private bool isPlayer(string whichPlayer, XYLocation loc)
        {
            string[] _whichRow = whichRow(loc.getYCoOrdinate());

            return(_whichRow[loc.getXCoOrdinate()].Equals(whichPlayer));
        }
Esempio n. 17
0
        private string whichPlayer(XYLocation loc)
        {
            string[] _whichRow = whichRow(loc.getYCoOrdinate());

            return(_whichRow[loc.getXCoOrdinate()]);
        }
Esempio n. 18
0
 private bool isLegalPlace(XYLocation forPlace)
 {
     if (forPlace.getXCoOrdinate() >= 0 && forPlace.getXCoOrdinate() < this.boardSize && forPlace.getYCoOrdinate() >= 0 && forPlace.getYCoOrdinate() < this.boardSize)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 19
0
 public bool queenExistsAt(XYLocation l)
 {
     return(queenExistsAt(l.getXCoOrdinate(), l.getYCoOrdinate()));
 }
Esempio n. 20
0
        private bool isEmpty(XYLocation loc)
        {
            string[] _whichRow = whichRow(loc.getYCoOrdinate());

            return(_whichRow[loc.getXCoOrdinate()] == " ");
        }
 public int getValueAt(XYLocation loc)
 {
     return(getValueAt(loc.getXCoOrdinate(), loc.getYCoOrdinate()));
 }
Esempio n. 22
0
        public override GameState makeMove(GameState state, Object o)
        {
            XYLocation loc = (XYLocation)o;

            return(makeMove(state, loc.getXCoOrdinate(), loc.getYCoOrdinate()));
        }