Example #1
0
 public void RemoveQueenFrom(XYLocation l)
 {
     if (squares[l.XCoordinate, l.YCoordinate] == 1)
     {
         squares[l.XCoordinate, l.YCoordinate] = 0;
     }
 }
Example #2
0
 /** Column and row indices start with 0! */
 public void addQueenAt(XYLocation l)
 {
     if (!(queenExistsAt(l)))
     {
         squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 1;
     }
 }
Example #3
0
        public void testEquality()
        {
            XYLocation loc1 = new XYLocation(3, 4);
            XYLocation loc2 = new XYLocation(3, 4);

            Assert.AreEqual(loc1, loc2);
        }
Example #4
0
 public void removeQueenFrom(XYLocation l)
 {
     if (squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] == 1)
     {
         squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 0;
     }
 }
Example #5
0
 public void removeQueenFrom(XYLocation l)
 {
     if (board[l.getXCoOrdinate(), l.getYCoOrdinate()] == 1)
     {
         board[l.getXCoOrdinate(), l.getYCoOrdinate()] = 0;
     }
 }
Example #6
0
        public void mark(XYLocation loc, string symbol)
        {
            string[] _whichRow = null;
            _whichRow = whichRow(loc.getYCoOrdinate());

            _whichRow[loc.getXCoOrdinate()] = symbol;
        }
Example #7
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(System.Math.Sqrt((xdifference * xdifference) + (ydifference * ydifference)) <= radius);
        }
Example #8
0
 public void AddQueenAt(XYLocation l)
 {
     if (!(this.QueenExistsAt(l)))
     {
         squares[l.XCoordinate, l.YCoordinate] = 1;
     }
 }
Example #9
0
        public void testMinmaxValueCalculation()
        {
            MinimaxSearch <TicTacToeState, XYLocation, string> search = MinimaxSearch <TicTacToeState, XYLocation, string> .createFor(game);

            Assert.IsTrue(epsilon > System.Math.Abs(search.maxValue(state, TicTacToeState.X) - 0.5));
            Assert.IsTrue(epsilon > System.Math.Abs(search.minValue(state, TicTacToeState.O) - 0.5));

            // x o x
            // o o x
            // - - -
            // next move: x
            state.mark(0, 0); // x
            state.mark(1, 0); // o
            state.mark(2, 0); // x

            state.mark(0, 1); // o
            state.mark(2, 1); // x
            state.mark(1, 1); // o

            Assert.IsTrue(epsilon > System.Math.Abs(search.maxValue(state, TicTacToeState.X) - 1));
            Assert.IsTrue(epsilon > System.Math.Abs(search.minValue(state, TicTacToeState.O)));
            XYLocation action = search.makeDecision(state);

            Assert.AreEqual(new XYLocation(2, 2), action);
        }
Example #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));
        }
Example #11
0
 public void addQueenAt(XYLocation l)
 {
     if (!(queenExistsAt(l)))
     {
         board[l.getXCoOrdinate(), l.getYCoOrdinate()] = 1;
     }
 }
Example #12
0
        public GameState GetMove(GameState state, int x, int y)
        {
            GameState retVal   = null;
            var       loc      = new XYLocation(x, y);
            var       moves    = GetMoves(state);
            var       newMoves = (ArrayList)moves.Clone();

            if (moves.Contains(loc))
            {
                var index = newMoves.IndexOf(loc);
                newMoves.RemoveAt(index);

                retVal = new GameState();

                retVal["moves"] = newMoves;
                var newBoard = this.GetBoard(state).CloneBoard();
                if (GetPlayerToMove(state) == "X")
                {
                    newBoard.MarkX(x, y);
                    retVal["player"] = "O";
                }
                else
                {
                    newBoard.MarkO(x, y);
                    retVal["player"] = "X";
                }
                retVal["board"]   = newBoard;
                retVal["utility"] = ComputeUtility(newBoard, GetPlayerToMove(GetState()));
                retVal["level"]   = GetLevel(state) + 1;
            }
            return(retVal);
        }
Example #13
0
        public void testXYLocationAtributeSettingOnConstruction()
        {
            XYLocation loc = new XYLocation(3, 4);

            Assert.AreEqual(3, loc.GetXCoOrdinate());
            Assert.AreEqual(4, loc.GetYCoOrdinate());
        }
Example #14
0
        public GameState getMove(GameState state, int x, int y)
        {
            GameState  retVal   = null;
            XYLocation loc      = new XYLocation(x, y);
            List       moves    = getMoves(state);
            List       newMoves = (List)moves.clone();

            if (moves.contains(loc))
            {
                int index = newMoves.indexOf(loc);
                newMoves.remove(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", new int(computeUtility(newBoard,
                                                             getPlayerToMove(getState()))));
                retVal.put("level", new int(getLevel(state) + 1));
                // presentState = retVal;
            }
            return(retVal);
        }
Example #15
0
        public bool isSquareUnderAttack(XYLocation l)
        {
            int x = l.GetXCoOrdinate();
            int y = l.GetYCoOrdinate();

            return(isSquareHorizontallyAttacked(x, y) || isSquareVerticallyAttacked(x, y) ||
                   isSquareDiagonallyAttacked(x, y));
        }
Example #16
0
 public void MoveQueen(XYLocation from, XYLocation to)
 {
     if ((this.QueenExistsAt(from)) && (!(this.QueenExistsAt(to))))
     {
         this.RemoveQueenFrom(from);
         this.AddQueenAt(to);
     }
 }
Example #17
0
	public void testIsBlocked() {
		XYLocation loc = new XYLocation(5, 5);
		Assert.assertEquals(0, env.getObjectsAt(loc).size());
		Assert.assertEquals(false, env.isBlocked(loc));
		env.addObjectToLocation(new Wall(), loc);
		Assert.assertEquals(1, env.getObjectsAt(loc).size());
		Assert.assertEquals(true, env.isBlocked(loc));
	}
Example #18
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.
  */
 public void moveQueenTo(XYLocation l)
 {
     for (int i = 0; i < getSize(); ++i)
     {
         squares[l.GetXCoOrdinate(), i] = 0;
     }
     squares[l.GetXCoOrdinate(), l.GetYCoOrdinate()] = 1;
 }
Example #19
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;
 }
Example #20
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));
        }
Example #21
0
 public LaplaceFilter(int yPosition, int xPosition)
 {
     RetinalPosition = new XYLocation(yPosition, xPosition);
     Value           = 0.0;
     VarianceCharge  = 0.0;
     PulseCharge     = 0; //for now; ensures only one edge will be found
     DirectionRouter = GlobalLayersKnowledge.DirectionRouter;
 }
Example #22
0
 /// <summary>
 /// Moves the queen in the specified column (x-value of <paramref name="l"/>) to
 /// the specified row (y-value of <paramref name="l"/>). The action assumes a
 /// complete-state formulation of the n-queens problem.
 /// </summary>
 /// <param name="l"></param>
 public void MoveQueenTo(XYLocation l)
 {
     for (var i = 0; i < Size; i++)
     {
         squares[l.XCoordinate, i] = 0;
     }
     squares[l.XCoordinate, l.YCoordinate] = 1;
 }
Example #23
0
 public void moveQueen(XYLocation from, XYLocation to)
 {
     if ((queenExistsAt(from)) && (!(queenExistsAt(to))))
     {
         removeQueenFrom(from);
         addQueenAt(to);
     }
 }
Example #24
0
        public void moveObjectToAbsoluteLocation(IEnvironmentObject eo, XYLocation loc)
        {
            // Ensure the object is not already at a location
            envState.moveObjectToAbsoluteLocation(eo, loc);

            // Ensure is added to the environment
            AddEnvironmentObject(eo);
        }
Example #25
0
	public void testAddObjectTwice() {
		Assert.assertEquals(1, env.getAgents().size());
		XYLocation loc = new XYLocation(5, 5);
		AbstractAgent b = new MockAgent();
		env.addObjectToLocation(b, loc);
		Assert.assertEquals(2, env.getAgents().size());

		Assert.assertEquals(loc, env.getCurrentLocationFor(b));
	}
Example #26
0
        public void testMoveNonExistentQueen()
        {
            XYLocation from = new XYLocation(0, 0);
            XYLocation to   = new XYLocation(1, 1);

            board.moveQueen(from, to);

            Assert.AreEqual(0, board.getNumberOfQueensOnBoard());
        }
Example #27
0
        public bool IsSquareUnderAttack(XYLocation l)
        {
            int x = l.XCoordinate;
            int y = l.YCoordinate;

            return(this.IsSquareHorizontallyAttacked(x, y) ||
                   this.IsSquareVerticallyAttacked(x, y) || this.IsSquareDiagonallyAttacked(
                       x, y));
        }
Example #28
0
        public int GetNumberOfAttacksOn(XYLocation l)
        {
            var x = l.XCoordinate;
            var y = l.YCoordinate;

            return(this.NumberOfHorizontalAttacksOn(x, y)
                   + this.NumberOfVerticalAttacksOn(x, y)
                   + this.NumberOfDiagonalAttacksOn(x, y));
        }
Example #29
0
        public void testSimpleVerticalAttack()
        {
            XYLocation loc = new XYLocation(0, 0);

            board.addQueenAt(loc);
            Assert.AreEqual(0, board.getNumberOfAttacksOn(loc));
            Assert.AreEqual(1, board.getNumberOfAttacksOn(loc.Down()));
            Assert.AreEqual(1, board.getNumberOfAttacksOn(new XYLocation(0, 7)));
        }
Example #30
0
 public MacroSector(int yPosition, int xPosition)
 {
     Location       = new XYLocation(yPosition, xPosition);
     Receptors      = new List <Receptor>();
     LaplaceFilters = new List <LaplaceFilter>();
     DecayRate      = .2; //arbi
     Muscle         = GlobalLayersKnowledge.Muscle;
     SectorPlate    = GlobalLayersKnowledge.MacroPlate;
 }
Example #31
0
        public void testSimpleHorizontalAttack()
        {
            XYLocation loc = new XYLocation(0, 0);

            board.addQueenAt(loc);
            Assert.AreEqual(0, board.getNumberOfAttacksOn(loc));
            Assert.AreEqual(1, board.getNumberOfAttacksOn(new XYLocation(1, 0)));
            Assert.AreEqual(1, board.getNumberOfAttacksOn(loc.Right()));
            Assert.AreEqual(1, board.getNumberOfAttacksOn(new XYLocation(7, 0)));
        }
Example #32
0
 public void MoveObjectToAbsoluteLocation(IEnvironmentObject eo, XYLocation loc)
 {
     // Ensure is not already at another location
     foreach (var eos in this.objsAtLocation.Values.Where(eos => eos.Remove(eo)))
     {
         break; // Should only every be at 1 location
     }
     // Add it to the location specified
     this.GetObjectsAt(loc).Add(eo);
 }
Example #33
0
	public void testMoveObject() {
		XYLocation loc = new XYLocation(5, 5);
		env.moveObjectToAbsoluteLocation(a, loc);
		Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
		env.moveObject(a, XYLocation.Direction.North);
		Assert.assertEquals(new XYLocation(5, 4), env.getCurrentLocationFor(a));
		env.moveObject(a, XYLocation.Direction.East);
		Assert.assertEquals(new XYLocation(6, 4), env.getCurrentLocationFor(a));
		env.moveObject(a, XYLocation.Direction.South);
		Assert.assertEquals(new XYLocation(6, 5), env.getCurrentLocationFor(a));
		env.moveObject(a, XYLocation.Direction.West);
		Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
	}
Example #34
0
	public void testSimpleVerticalAttack() {
		XYLocation loc = new XYLocation(0, 0);
		board.addQueenAt(loc);
		Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down()));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(0, 7)));
	}
Example #35
0
	public void testMoveObjectToAbsoluteLocation() {
		XYLocation loc = new XYLocation(5, 5);
		env.moveObjectToAbsoluteLocation(a, loc);
		Assert.assertEquals(new XYLocation(5, 5), env.getCurrentLocationFor(a));
	}
Example #36
0
	public void testMoveWithBlockingWalls() {
		XYLocation loc = new XYLocation(5, 5);
		env.moveObjectToAbsoluteLocation(a, loc);
		XYLocation northLoc = new XYLocation(5, 6);
		XYLocation southLoc = new XYLocation(5, 4);
		XYLocation westLoc = new XYLocation(4, 5);

		env.addObjectToLocation(new Wall(), northLoc); // wall to the north of
		// object
		Assert.assertTrue(env.isBlocked(northLoc));
		env.addObjectToLocation(new Wall(), southLoc); // wall to the south of
		// object
		env.addObjectToLocation(new Wall(), westLoc); // wall to the west of
		// object
		Assert.assertEquals(4, env.getEnvironmentObjects().size());

		env.moveObject(a, XYLocation.Direction.North); // should not move
		env.moveObject(a, XYLocation.Direction.South); // should not move
		env.moveObject(a, XYLocation.Direction.West); // should not move
		env.moveObject(a, XYLocation.Direction.East); // SHOULD move
		Assert.assertEquals(new XYLocation(6, 5), env.getCurrentLocationFor(a));
	}
Example #37
0
	public void testMoveQueen() {

		XYLocation from = new XYLocation(0, 0);
		XYLocation to = new XYLocation(1, 1);

		board.addQueenAt(from);
		Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
		Assert.assertTrue(board.queenExistsAt(from));
		Assert.assertFalse(board.queenExistsAt(to));

		board.moveQueen(from, to);
		Assert.assertEquals(1, board.getNumberOfQueensOnBoard());
		Assert.assertFalse(board.queenExistsAt(from));
		Assert.assertTrue(board.queenExistsAt(to));
	}
Example #38
0
	public void testMoveNonExistentQueen() {

		XYLocation from = new XYLocation(0, 0);
		XYLocation to = new XYLocation(1, 1);
		board.moveQueen(from, to);

		Assert.assertEquals(0, board.getNumberOfQueensOnBoard());
	}
Example #39
0
	public void testSimpleHorizontalAttack() {
		XYLocation loc = new XYLocation(0, 0);
		board.addQueenAt(loc);
		Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(1, 0)));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.right()));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(7, 0)));
	}
Example #40
0
	public void testGetObjectsNear() {
		XYLocation loc = new XYLocation(5, 5);
		env.moveObjectToAbsoluteLocation(a, loc);
		AbstractAgent b = new MockAgent();
		AbstractAgent c = new MockAgent();
		Wall w1 = new Wall();

		env.addObjectToLocation(b, new XYLocation(7, 4));
		env.addObjectToLocation(c, new XYLocation(5, 7));
		env.addObjectToLocation(w1, new XYLocation(3, 10));

		// at this point agent A should be able to see B and C but not the wall
		// with a "vision radius" of 3
		Set<EnvironmentObject> visibleToA = env.getObjectsNear(a, 3);
		Assert.assertEquals(2, visibleToA.size());
		// agent B should be able to see A only
		Set<EnvironmentObject> visibleToB = env.getObjectsNear(b, 3);
		Assert.assertEquals(1, visibleToB.size());

		// move B South
		env.moveObject(b, XYLocation.Direction.South);
		// at this point both a and c should be visible to b
		visibleToB = env.getObjectsNear(b, 3);
		Assert.assertEquals(2, visibleToB.size());
		// move c near the wall
		env.moveObjectToAbsoluteLocation(c, new XYLocation(3, 11));
		// only the wall should be visible
		Set<EnvironmentObject> visibleToC = env.getObjectsNear(c, 3);
		Assert.assertEquals(1, visibleToC.size());
	}
Example #41
0
	public void testMultipleQueens() {
		XYLocation loc1 = new XYLocation(3, 3);
		board.addQueenAt(loc1);
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1.right()));

		board.addQueenAt(loc1.right().right());
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc1));
		Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1.right()));

		board.addQueenAt(loc1.right().down());
		Assert.assertEquals(2, board.getNumberOfAttacksOn(loc1));
		Assert.assertEquals(3, board.getNumberOfAttacksOn(loc1.right()));
		Assert
				.assertEquals(2, board.getNumberOfAttacksOn(loc1.right()
						.right()));
	}
Example #42
0
	public void testSimpleDiagonalAttack() {
		XYLocation loc = new XYLocation(3, 3);
		board.addQueenAt(loc);
		Assert.assertEquals(0, board.getNumberOfAttacksOn(loc));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down().right()));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.down().left()));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.up().left()));
		Assert.assertEquals(1, board.getNumberOfAttacksOn(loc.up().right()));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(7, 7)));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(0, 0)));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(6, 0)));
		Assert
				.assertEquals(1, board
						.getNumberOfAttacksOn(new XYLocation(0, 6)));
	}
Example #43
0
	public void testGetObjectsAt() {
		XYLocation loc = new XYLocation(5, 7);
		env.moveObjectToAbsoluteLocation(a, loc);
		Assert.assertEquals(1, env.getObjectsAt(loc).size());
		AbstractAgent b = new MockAgent();
		env.addObjectToLocation(b, loc);
		Assert.assertEquals(2, env.getObjectsAt(loc).size());
	}