Esempio n. 1
0
// tests the Board::print function
void Board::TestPrintBoard(ostream &out)
{
    out << "Test Print board<br>";
    
    BoardState state;
    
    state.robots[0].x = 0;
    state.robots[0].y = 0;
    state.robots[1].x = 3;
    state.robots[1].y = 3;
    state.robots[2].x = 2;
    state.robots[2].y = 1;
    
    BoardLocType brd[25] = 
    {
         LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED ,
         LEFT_BLOCKED, RIGHT_BLOCKED, LEFT_BLOCKED | BOTTOM_BLOCKED, EMPTY, RIGHT_BLOCKED,
         LEFT_BLOCKED, EMPTY, TOP_BLOCKED | RIGHT_BLOCKED, LEFT_BLOCKED, RIGHT_BLOCKED,
         LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
         BOTTOM_BLOCKED | LEFT_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED | RIGHT_BLOCKED
    };
    
    Board testBoard(5, 5, Location(4, 3), brd);
    

    
    testBoard.print(state, out);
    
    out << "end Test Print board<br><br><br>";
    
}
void Nqueen(int num){
	if( num == n ){
		printBoard();
		NumOfSolutions++;
		return;
	}
	for(int i= 0; i< n; i++){
		Cqueen[num]= i;
		if( testBoard(num+1) ){
			Nqueen(num+1);
		}
	}
}
Esempio n. 3
0
// test the board::get function
void Board::TestGet(ostream &out)
{
    
    
    // define base state
    BoardLocType brd[4] =
    {
        LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED,
        LEFT_BLOCKED | BOTTOM_BLOCKED, RIGHT_BLOCKED | BOTTOM_BLOCKED
    };
    
    Board testBoard(2, 2, Location(), brd);
    
    assert(testBoard.get(0, 0) == (LEFT_BLOCKED | TOP_BLOCKED));
    assert(testBoard.get(0, 1) == (LEFT_BLOCKED | BOTTOM_BLOCKED));
    assert(testBoard.get(1, 0) == (TOP_BLOCKED | RIGHT_BLOCKED));
    assert(testBoard.get(1, 1) == (RIGHT_BLOCKED | BOTTOM_BLOCKED));
    
    
    
    // define base state
    BoardLocType brd2[25] =
    {
        LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED,
        LEFT_BLOCKED, RIGHT_BLOCKED, LEFT_BLOCKED | BOTTOM_BLOCKED, EMPTY, RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, TOP_BLOCKED | RIGHT_BLOCKED, LEFT_BLOCKED, RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
        BOTTOM_BLOCKED | LEFT_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED | RIGHT_BLOCKED
    };
    
    Board testBoard2(5, 5, Location(), brd2);
    
    assert(testBoard2.get(0, 0) == (LEFT_BLOCKED | TOP_BLOCKED));
    assert(testBoard2.get(2, 1) == (LEFT_BLOCKED | BOTTOM_BLOCKED));
    assert(testBoard2.get(3, 3) == (EMPTY));
    assert(testBoard2.get(0, 4) == (BOTTOM_BLOCKED | LEFT_BLOCKED));
}
Esempio n. 4
0
int main() {

   //A test shape - can be easily changed to produce different test cases.
   std::vector<std::vector<bool>> test5x5Shape = 

                              {
                                 {0,0,0,0,0},
                                 {0,0,0,0,0},
                                 {0,1,1,1,0},
                                 {0,0,0,0,0},
                                 {0,0,0,0,0}
                              };

   //A test shape - can be easily changed to produce different test cases.
   std::vector<std::vector<bool>> test22x80Shape = 

                              {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,1,1,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
};

std::cout << "rows in test22x80Shape = " << test22x80Shape.size()
            << std::endl;
std::cout << "cols in test22x80Shape = " << test22x80Shape[0].size()
            << std::endl;
  
   //Test config (5 x 5)
   //peteredw::Config testConfig(test5x5Shape, "5 x 5 test shape");

   //Test config (22 x 80)
   peteredw::Config testConfig(test22x80Shape, "22 x 80 test shape");
   
   std::cout << testConfig.title() << std::endl;

   std::vector<std::vector<peteredw::Cell>> testVector = testConfig.cells();

   //Tests Config constructor and cells() accessor.
   for (unsigned int i = 0; i < (testVector).size(); i++) {
   
      for (unsigned int j = 0; j < (testVector)[0].size(); j++)
         std::cout << (testVector)[i][j].status();

      std::cout << std::endl;

      }
/*
   //Tests Cell::count_neighbors(), which must be made public for this
   //test to work.
   {std::cout
         << (testVector)[4][0].count_neighbors(
               testVector, 4, 0)
         << std::endl;}
    
    //Tests Cell::next(), which must be public for this test to work.
         std::cout
               << (testVector)[1][1].status() << std::endl;
         std::cout
                << (testVector)[1][1].next(testVector, 1, 1) << std::endl;
*/

   //Test Board::next()
   try {
   std::cout << "Initializing testBoard with testConfig.\n";
   peteredw::Board testBoard(testConfig);

   std::cout << "Printing nextGen from testBoard on first generation.\n";
   testBoard.print();

   std::cout << "Calling testBoard.next() to get 2nd generation.\n";
   testBoard.next();

   std::cout << "Printing nextGen from testBoard for second time.\n";
   testBoard.print();

   std::cout << "Calling testBoard.next() to get 3rd generation.\n";
   testBoard.next();

   std::cout << "Printing nextGen from testBoard for third time.\n";
   testBoard.print();
   }

   catch (peteredw::BoardStatic) {

      std::cout << "No change in board from one gen to next.\n";

   }


   return 0;

   }
Esempio n. 5
0
// test the WhereCanThisPieceMove function. Note that it does not assert, but rather
// outputs the results to out for user inspection. 
void Board::TestWhereCanThisPieceMove(ostream &out)
{
    
    
    
    // define base state
    BoardLocType brd[25] =
    {
         LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED,
         LEFT_BLOCKED, RIGHT_BLOCKED, LEFT_BLOCKED | BOTTOM_BLOCKED, EMPTY, RIGHT_BLOCKED,
         LEFT_BLOCKED, EMPTY, TOP_BLOCKED | RIGHT_BLOCKED, LEFT_BLOCKED, RIGHT_BLOCKED,
         LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
         BOTTOM_BLOCKED | LEFT_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED | RIGHT_BLOCKED
    };
    
    Board testBoard(5, 5, Location(), brd);
    
    
    
    Location lowerEdge;
    Location upperEdge;
    
    BoardState state;
    
    state.robots[0].x = 2;
    state.robots[0].y = 3;
    state.robots[1].x = 2;
    state.robots[1].y = 1;
    state.robots[2].x = 3;
    state.robots[2].y = 3;

    
    
    vector<Location> ret;
    vector<Location> expected;
    
    //wall top
    state.robots[0].x = 2;
    state.robots[0].y = 3;
    testBoard.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(0,3));
    expected.push_back(Location(2, 2));
    expected.push_back(Location(2, 4));
    testLocationVector(expected, ret, out, testBoard, state, "wall top");
    expected.clear();
    ret.clear();
    
    //wall left
    state.robots[0].x = 4;
    state.robots[0].y = 1;
    testBoard.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(4, 0));
    expected.push_back(Location(3, 1));
    expected.push_back(Location(4, 4));
    testLocationVector(expected, ret, out, testBoard, state, "wall left");
    expected.clear();
    ret.clear();
    
    //wall right
    state.robots[0].x = 1;
    state.robots[0].y = 2;
    testBoard.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(0, 2));
    expected.push_back(Location(1, 0));
    expected.push_back(Location(2, 2));
    expected.push_back(Location(1, 4));
    testLocationVector(expected, ret, out, testBoard, state, "wall right");
    expected.clear();
    ret.clear();
    
    //wall bottom
    state.robots[0].x = 2;
    state.robots[0].y = 0;
    testBoard.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(0,0));
    expected.push_back(Location(4,0));
    testLocationVector(expected, ret, out, testBoard, state, "wall bottom");
    expected.clear();
    ret.clear();
    
    //walls all around
    BoardLocType brdAllWallsAround[25] =
    {
        LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, BOTTOM_BLOCKED, EMPTY, RIGHT_BLOCKED,
        LEFT_BLOCKED, RIGHT_BLOCKED, TOP_BLOCKED | LEFT_BLOCKED | RIGHT_BLOCKED | BOTTOM_BLOCKED, LEFT_BLOCKED, RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, TOP_BLOCKED, EMPTY, RIGHT_BLOCKED,
        BOTTOM_BLOCKED | LEFT_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED | RIGHT_BLOCKED
    };
    Board testBoardAllWallsAround(5, 5, Location(), brdAllWallsAround);
    state.robots[0].x = 2;
    state.robots[0].y = 2;
    state.robots[1].x = 0;
    state.robots[1].y = 0;
    state.robots[2].x = 4;
    state.robots[2].y = 4;
    testBoardAllWallsAround.WhereCanThisPieceMove(state, 0, ret);
    // the piece can't move anywhere
    testLocationVector(expected, ret, out, testBoardAllWallsAround, state, "walls all around");
    expected.clear();
    ret.clear();
    
    //robots all around (part 1 - left/right)
    
    BoardLocType brdAllRobotsAround[25] =
    {
        LEFT_BLOCKED | TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED, TOP_BLOCKED | RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
        LEFT_BLOCKED, EMPTY, EMPTY, EMPTY, RIGHT_BLOCKED,
        BOTTOM_BLOCKED | LEFT_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED, BOTTOM_BLOCKED | RIGHT_BLOCKED
    };
    Board testBoardAllRobotsAround(5, 5, Location(), brdAllRobotsAround);
    state.robots[0].x = 2;
    state.robots[0].y = 1;
    state.robots[1].x = 3;
    state.robots[1].y = 1;
    state.robots[2].x = 1;
    state.robots[2].y = 1;
    testBoardAllRobotsAround.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(2,0));
    expected.push_back(Location(2,4));
    testLocationVector(expected, ret, out, testBoardAllRobotsAround, state, "robots all around (part 1 - left/right)");
    expected.clear();
    ret.clear();

    //robots all around (part 2 - top/bottom)
    state.robots[0].x = 2;
    state.robots[0].y = 2;
    state.robots[1].x = 2;
    state.robots[1].y = 1;
    state.robots[2].x = 2;
    state.robots[2].y = 3;
    testBoardAllRobotsAround.WhereCanThisPieceMove(state, 0, ret);
    expected.push_back(Location(0,2));
    expected.push_back(Location(4,2));
    testLocationVector(expected, ret, out, testBoardAllRobotsAround, state, "robots all around (part 2 - top/bottom)");
    expected.clear();
    ret.clear();
    
    
}
Esempio n. 6
0
void Board::TestDetermineEdges()
{
    BoardLocType brd[25]; 
    Board testBoard(5, 5, Location(), brd);
    // define base state
    Location lowerEdge;
    Location upperEdge;
    
    BoardState state;
    
    state.robots[0].x = 2;
    state.robots[0].y = 3;
    state.robots[1].x = 2;
    state.robots[1].y = 1;
    state.robots[2].x = 3;
    state.robots[2].y = 3;
    
    //no move case - piece above & right
    testBoard.DetermineEdges(0, state, 2, 3, lowerEdge, upperEdge);
    assert(lowerEdge.x == 0);
    assert(lowerEdge.y == 2);
    assert(upperEdge.x == 2);
    assert(upperEdge.y == testBoard.size.y - 1);
    lowerEdge.x = INVALID_LOC;
    lowerEdge.y = INVALID_LOC;
    upperEdge.x = INVALID_LOC;
    upperEdge.y = INVALID_LOC;
    
    //no move case - piece below & left
    state.robots[1].x = 2;
    state.robots[1].y = 4;
    state.robots[2].x = 1;
    state.robots[2].y = 3;
    testBoard.DetermineEdges(0, state, 2, 3, lowerEdge, upperEdge);
    assert(lowerEdge.x == 2);
    assert(lowerEdge.y == 0);
    assert(upperEdge.x == testBoard.size.x - 1);
    assert(upperEdge.y == 3);
    lowerEdge.x = INVALID_LOC;
    lowerEdge.y = INVALID_LOC;
    upperEdge.x = INVALID_LOC;
    upperEdge.y = INVALID_LOC;
    
    //two robots on the same axis - later one wins
    state.robots[1].x = 0;
    state.robots[1].y = 3;
    state.robots[2].x = 1;
    state.robots[2].y = 3;
    testBoard.DetermineEdges(0, state, 2, 3, lowerEdge, upperEdge);
    assert(lowerEdge.x == 2);
    assert(lowerEdge.y == 0);
    assert(upperEdge.x == testBoard.size.x - 1);
    assert(upperEdge.y == testBoard.size.y - 1);    
    lowerEdge.x = INVALID_LOC;
    lowerEdge.y = INVALID_LOC;
    upperEdge.x = INVALID_LOC;
    upperEdge.y = INVALID_LOC;
    
    //two robots on the same axis - earlier one wins
    state.robots[1].x = 1;
    state.robots[1].y = 3;
    state.robots[2].x = 0;
    state.robots[2].y = 3;
    testBoard.DetermineEdges(0, state, 2, 3, lowerEdge, upperEdge);
    assert(lowerEdge.x == 2);
    assert(lowerEdge.y == 0);
    assert(upperEdge.x == testBoard.size.x - 1);
    assert(upperEdge.y == testBoard.size.y - 1);    
    lowerEdge.x = INVALID_LOC;
    lowerEdge.y = INVALID_LOC;
    upperEdge.x = INVALID_LOC;
    upperEdge.y = INVALID_LOC;   
    
    
}
void TicTacToeRulesEngine::genNextMoves(const Grid *current, Grid **&nextMoves, int *&lastMoves, Elements::PlayerType currentPlayer, int &numNextStates) const
{
    numNextStates = current->numPiecesOfType(Elements::EMPTY);

    if(testBoard(current) != Elements::NORMAL)
    {
        numNextStates = 0;
        return;
    }

#ifdef DEBUG_C4GENNEXTMOVES
    printLine3("There are ", numNextStates, " legal moves from this state.");
#endif

    nextMoves = new Grid*[numNextStates];
    lastMoves = new int[numNextStates];

    for(int x = 0; x < numNextStates; ++x)
    {
        nextMoves[x] = new TicTacToeGrid();
        //Deep copy of the current grid to each new grid.
        *nextMoves[x] = *current;
    }

    int stateCount = 0;
    int moveIndex = 0;

    for(int x = 0; x < 3; ++x)
    {
        for(int y = 0; y < 3; ++y)
        {
            //Keep looping through the squares.  There should be one possible move for each Elements::EMPTY
            //space.  StateCount will only increment when an Elements::EMPTY space is filled.  Once there are
            //no more spaces, the loop will break.
            if(stateCount >= numNextStates)
                return;

            if(nextMoves[stateCount]->squares[x][y] == Elements::EMPTY)
            {
                nextMoves[stateCount]->squares[x][y] = (Elements::GenericPieceType)currentPlayer;

                //Store the index of the most recently used square.
                lastMoves[stateCount] = moveIndex;
                ++stateCount;
            }

            //A simple counter to keep track of the current square.
            ++moveIndex;
        }
    }

#ifdef DEBUG_TTTGENNEXTMOVES
    //Display the board.
    for(int y = 0; y < 3; ++y)
    {
        int nextStateIndex = 0;
        while(nextStateIndex < numNextStates)
        {
            for(int x = 0; x < 3; ++x)
            {
                print2(nextMoves[nextStateIndex]->squares[x][y], " ");
            }
            print("\t");
            ++nextStateIndex;
        }
        print("\n");
    }
    printLine("\n");
#endif

    return;
}