public override bool Equals(Object o) { XYLocation anotherLoc = (XYLocation)o; return((anotherLoc.getXCoOrdinate() == xCoOrdinate) && (anotherLoc .getYCoOrdinate() == yCoOrdinate)); }
public XYEnvironment(int width, int height) { this.width = width; this.height = height; this.defaultLocation = new XYLocation(1, 1); }
public void removeQueenFrom(XYLocation l) { if (board[l.getXCoOrdinate(),l.getYCoOrdinate()] == 1) { board[l.getXCoOrdinate(),l.getYCoOrdinate()] = 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); }
public void moveQueen(XYLocation from, XYLocation to) { if ((queenExistsAt(from)) && (!(queenExistsAt(to)))) { removeQueenFrom(from); addQueenAt(to); } }
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); }
public void moveObject(Agent a, String direction) { XYLocation presentLocation = (XYLocation)a.getAttribute(LOCATION); XYLocation locationToMoveTo = presentLocation.locationAt(direction); if (!(isBlocked(locationToMoveTo))) { moveObjectToAbsoluteLocation(a, locationToMoveTo); } }
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); }
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); }
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; }
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); } }
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; }
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; }
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; }
public void moveObjectToAbsoluteLocation(Agent a, XYLocation loc) { a.setAttribute(LOCATION, loc); }
public void addQueenAt(XYLocation l) { if (!(queenExistsAt(l))) board[l.getXCoOrdinate(),l.getYCoOrdinate()] = 1; }
public void addAgent(Agent a, XYLocation loc) { base.addAgent(a, LOCATION, loc); }
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; }
private bool isPlayer(string whichPlayer, XYLocation loc) { string[] _whichRow = whichRow(loc.getYCoOrdinate()); return (_whichRow[loc.getXCoOrdinate()].Equals(whichPlayer)); }
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; }
public void mark(XYLocation loc, string symbol) { string[] _whichRow = null; _whichRow = whichRow(loc.getYCoOrdinate()); _whichRow[loc.getXCoOrdinate()] = symbol; }
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; }
public int getValueAt(XYLocation loc) { return getValueAt(loc.getXCoOrdinate(), loc.getYCoOrdinate()); }
public bool isSquareUnderAttack(XYLocation l) { int x = l.getXCoOrdinate(); int y = l.getYCoOrdinate(); return (isSquareHorizontallyAttacked(x, y) || isSquareVerticallyAttacked(x, y) || isSquareDiagonallyAttacked( x, y)); }
public void addObject(EnvironmentObject o, XYLocation loc) { base.addObject(o, LOCATION, loc); }
public int getNumberOfAttacksOn(XYLocation l) { int x = l.getXCoOrdinate(); int y = l.getYCoOrdinate(); return numberOfHorizontalAttacksOn(x, y) + numberOfVerticalAttacksOn(x, y) + numberOfDiagonalAttacksOn(x, y); }
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; }
public void movePiece(XYLocation from, XYLocation to) { mark(to,whichPlayer(from)); mark(from," "); }
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; }
public bool queenExistsAt(XYLocation l) { return (queenExistsAt(l.getXCoOrdinate(), l.getYCoOrdinate())); }
private bool isEmpty(XYLocation loc) { string[] _whichRow = whichRow(loc.getYCoOrdinate()); return (_whichRow[loc.getXCoOrdinate()] == " "); }
private string whichPlayer(XYLocation loc) { string[] _whichRow = whichRow(loc.getYCoOrdinate()); return (_whichRow[loc.getXCoOrdinate()]); }