Beispiel #1
0
        public override bool Equals(Object o)
        {
            XYLocation anotherLoc = (XYLocation)o;

            return((anotherLoc.getXCoOrdinate() == xCoOrdinate) && (anotherLoc
                                                                    .getYCoOrdinate() == yCoOrdinate));
        }
Beispiel #2
0
		public XYEnvironment(int width, int height) 
		{

			this.width = width;
			this.height = height;
			this.defaultLocation = new XYLocation(1, 1);
		}
Beispiel #3
0
		public void removeQueenFrom(XYLocation l) 
		{

			if (board[l.getXCoOrdinate(),l.getYCoOrdinate()] == 1) 
			{
				board[l.getXCoOrdinate(),l.getYCoOrdinate()] = 0;
			}
		}
Beispiel #4
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);

		}
Beispiel #5
0
		public void moveQueen(XYLocation from, XYLocation to) 
		{

			if ((queenExistsAt(from)) && (!(queenExistsAt(to)))) 
			{
				removeQueenFrom(from);
				addQueenAt(to);
			}
		}
Beispiel #6
0
        private bool withinRadius(int radius, XYLocation agentLocation,
                                  XYLocation objectLocation)
        {
            int dist = Calculator.calculateSquareOfDistanceBetweenLocations(
                agentLocation, objectLocation);
            int  radiusSquared = radius * radius;
            bool withinRadius  = (dist <= radiusSquared);

            return(withinRadius);
        }
Beispiel #7
0
        public void moveObject(Agent a, String direction)
        {
            XYLocation presentLocation  = (XYLocation)a.getAttribute(LOCATION);
            XYLocation locationToMoveTo = presentLocation.locationAt(direction);

            if (!(isBlocked(locationToMoveTo)))
            {
                moveObjectToAbsoluteLocation(a, locationToMoveTo);
            }
        }
Beispiel #8
0
        public ArrayList getObjectsAt(XYLocation loc)
        {
            ArrayList retval = new ArrayList();

            ArrayList all = getAllObjects();

            foreach (ObjectWithDynamicAttributes obj in all)
            {
                XYLocation objLoc = (XYLocation)obj.getAttribute(LOCATION);
                if (objLoc.Equals(loc))
                {
                    retval.Add(obj);
                }
            }
            return(retval);
        }
Beispiel #9
0
        public bool isBlocked(XYLocation loc)
        {
            bool      retval = false;
            ArrayList objs   = this.getObjectsAt(loc);

            for (int i = 0; i < objs.Count; i++)
            {
                EnvironmentObject eo = (EnvironmentObject)objs[i];
                //if (eo instanceof Wall)
                if (eo is Wall)
                {
                    retval = true;
                }
            }
            return(retval);
        }
Beispiel #10
0
		public ArrayList getObjectsAt(XYLocation loc) 
		{

			ArrayList retval = new ArrayList();

			ArrayList all = getAllObjects();
			foreach (ObjectWithDynamicAttributes obj in all) 
			{
				XYLocation objLoc = (XYLocation) obj.getAttribute(LOCATION);
				if (objLoc.Equals(loc)) 
				{
					retval.Add(obj);
				}

			}
			return retval;
		}
Beispiel #11
0
        public void makePerimeter()
        {
            for (int i = 0; i < width; i++)
            {
                XYLocation loc  = new XYLocation(i, 0);
                XYLocation loc2 = new XYLocation(i, height - 1);
                addObject(new Wall(), loc);
                addObject(new Wall(), loc2);
            }

            for (int i = 0; i < height; i++)
            {
                XYLocation loc  = new XYLocation(0, i);
                XYLocation loc2 = new XYLocation(width - 1, i);
                addObject(new Wall(), loc);
                addObject(new Wall(), loc2);
            }
        }
Beispiel #12
0
		public TicTacToe() 
		{
			ArrayList moves = new ArrayList();
			for (int i = 0; i < 3; i++) 
			{
				for (int j = 0; j < 3; j++) 
				{
					XYLocation loc = new XYLocation(i, j);
					moves.Add(loc);
				}
			}
			initialState.put("moves", moves);
			initialState.put("player", "X");
			initialState.put("utility", 0);
			initialState.put("board", new TicTacToeBoard());
			initialState.put("level", 0);
			presentState = initialState;
		}
Beispiel #13
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;
		}
Beispiel #14
0
        public ArrayList getObjectsNear(Agent agent, int radius)
        {
            ArrayList retval = new ArrayList();

            XYLocation agentLocation = (XYLocation)agent.getAttribute(LOCATION);

            ArrayList all = getAllObjects();

            foreach (ObjectWithDynamicAttributes a in all)
            {
                if (!(a.Equals(agent)))
                {
                    XYLocation otherAgentLocation = (XYLocation)a
                                                    .getAttribute(LOCATION);
                    if (withinRadius(radius, agentLocation, otherAgentLocation))
                    {
                        retval.Add(a);
                    }
                }
            }
            return(retval);
        }
		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;
		}
Beispiel #16
0
		public void moveObjectToAbsoluteLocation(Agent a, XYLocation loc) 
		{

			a.setAttribute(LOCATION, loc);

		}
Beispiel #17
0
		public void addQueenAt(XYLocation l) 
		{

			if (!(queenExistsAt(l)))
				board[l.getXCoOrdinate(),l.getYCoOrdinate()] = 1;
		}
Beispiel #18
0
 public void addAgent(Agent a, XYLocation loc)
 {
     base.addAgent(a, LOCATION, loc);
 }
Beispiel #19
0
		public void addAgent(Agent a, XYLocation loc) 
		{
			base.addAgent(a, LOCATION, loc);
		}
Beispiel #20
0
		private ArrayList getMoves(XYLocation forPiece) 
		{
			ArrayList retVal = new ArrayList();

			if (this.isPlayer(B,forPiece))
			{
				//if the piece below is empty, add it
				if (this.isLegalPlace(forPiece.south()) && this.isEmpty(forPiece.south()))
					retVal.Add(forPiece.south());
				//if the south diagonals are white, add them
				if (this.isLegalPlace(forPiece.southwest()) && this.isPlayer(W,forPiece.southwest()))
					retVal.Add(forPiece.southwest());
				if (this.isLegalPlace(forPiece.southeast()) && this.isPlayer(W,forPiece.southeast()))
					retVal.Add(forPiece.southeast());
			}
			else
			{
				//if the piece above is empty, add it
				if (this.isLegalPlace(forPiece.north()) && this.isEmpty(forPiece.north()))
					retVal.Add(forPiece.north());
				//if the north diagonals are black, add them
				if (this.isLegalPlace(forPiece.northwest()) && this.isPlayer(B,forPiece.northwest()))
					retVal.Add(forPiece.northwest());
				if (this.isLegalPlace(forPiece.northeast()) && this.isPlayer(B,forPiece.northeast()))
					retVal.Add(forPiece.northeast());
			}

			return retVal;
		}
Beispiel #21
0
		private bool isPlayer(string whichPlayer, XYLocation loc) 
		{
			string[] _whichRow = whichRow(loc.getYCoOrdinate());

			return (_whichRow[loc.getXCoOrdinate()].Equals(whichPlayer));
		}
Beispiel #22
0
		private bool withinRadius(int radius, XYLocation agentLocation,
			XYLocation objectLocation) 
		{
			int dist = Calculator.calculateSquareOfDistanceBetweenLocations(
				agentLocation, objectLocation);
			int radiusSquared = radius * radius;
			bool withinRadius = (dist <= radiusSquared);
			return withinRadius;
		}
Beispiel #23
0
		public void mark(XYLocation loc, string symbol) 
		{
			string[] _whichRow = null;
			_whichRow = whichRow(loc.getYCoOrdinate());

			_whichRow[loc.getXCoOrdinate()] = symbol;
		}
Beispiel #24
0
		public ArrayList getPositions() 
		{
			ArrayList retVal = new ArrayList();
			for (int i = 0; i < 9; i++) 
			{
				int[] res = xycoordinatesFromAbsoluteCoordinate(getPositionOf(i));
				XYLocation loc = new XYLocation(res[0], res[1]);
				retVal.Add(loc);

			}
			return retVal;
		}
Beispiel #25
0
		public int getValueAt(XYLocation loc) 
		{
			return getValueAt(loc.getXCoOrdinate(), loc.getYCoOrdinate());
		}
Beispiel #26
0
		public bool isSquareUnderAttack(XYLocation l) 
		{

			int x = l.getXCoOrdinate();
			int y = l.getYCoOrdinate();
			return (isSquareHorizontallyAttacked(x, y)
				|| isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked(
				x, y));
		}
Beispiel #27
0
 public XYEnvironment(int width, int height)
 {
     this.width           = width;
     this.height          = height;
     this.defaultLocation = new XYLocation(1, 1);
 }
Beispiel #28
0
 public void addObject(EnvironmentObject o, XYLocation loc)
 {
     base.addObject(o, LOCATION, loc);
 }
Beispiel #29
0
		public int getNumberOfAttacksOn(XYLocation l) 
		{

			int x = l.getXCoOrdinate();
			int y = l.getYCoOrdinate();
			return numberOfHorizontalAttacksOn(x, y)
				+ numberOfVerticalAttacksOn(x, y)
				+ numberOfDiagonalAttacksOn(x, y);
		}
Beispiel #30
0
		public bool isBlocked(XYLocation loc) 
		{
			bool retval = false;
			ArrayList objs = this.getObjectsAt(loc);

			for (int i = 0; i < objs.Count; i++) 
			{
				EnvironmentObject eo = (EnvironmentObject) objs[i];
				//if (eo instanceof Wall) 
				if (eo is Wall)
				{
					retval = true;
				}
			}
			return retval;
		}
Beispiel #31
0
		public void movePiece(XYLocation from, XYLocation to)
		{
			mark(to,whichPlayer(from));
			mark(from," ");
		}
Beispiel #32
0
		public void makePerimeter() 
		{
			for (int i = 0; i < width; i++) 
			{
				XYLocation loc = new XYLocation(i, 0);
				XYLocation loc2 = new XYLocation(i, height - 1);
				addObject(new Wall(), loc);
				addObject(new Wall(), loc2);
			}

			for (int i = 0; i < height; i++) 
			{
				XYLocation loc = new XYLocation(0, i);
				XYLocation loc2 = new XYLocation(width - 1, i);
				addObject(new Wall(), loc);
				addObject(new Wall(), loc2);
			}

		}
Beispiel #33
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;
		}
Beispiel #34
0
		public bool queenExistsAt(XYLocation l) 
		{

			return (queenExistsAt(l.getXCoOrdinate(), l.getYCoOrdinate()));
		}
Beispiel #35
0
		private bool isEmpty(XYLocation loc)
		{
			string[] _whichRow = whichRow(loc.getYCoOrdinate());

			return (_whichRow[loc.getXCoOrdinate()] == " ");
		}
Beispiel #36
0
		public void addObject(EnvironmentObject o, XYLocation loc) 
		{

			base.addObject(o, LOCATION, loc);
		}
Beispiel #37
0
		private string whichPlayer(XYLocation loc)
		{
			string[] _whichRow = whichRow(loc.getYCoOrdinate());

			return (_whichRow[loc.getXCoOrdinate()]);
		}
Beispiel #38
0
 public void moveObjectToAbsoluteLocation(Agent a, XYLocation loc)
 {
     a.setAttribute(LOCATION, loc);
 }