vector < vector <GamePositionOnBoard> > DetailsFromBoardDataSource::getTetraminoDetailsInGame()
{

	vector < vector <GamePositionOnBoard> > detailsInGameBoard = vector < vector <GamePositionOnBoard> >();

	GameBoard *extractedDetailsData = new GameBoard(_gameBoard->getGameBoardWidth() ,_gameBoard->getGameBoardHeight());

	for (int yIndex = 0; yIndex < _gameBoard->getGameBoardHeight(); yIndex++)
	{

		for (int xIndex = 0; xIndex < _gameBoard->getGameBoardWidth(); xIndex++)
		{
			Tetramino *tetraminoInBoard = _gameBoard->getTetraminoForXYposition(xIndex, yIndex);
			Tetramino *tetraminoInExtractedDetailsData = extractedDetailsData->getTetraminoForXYposition(xIndex, yIndex);


			if ((tetraminoInBoard->getTetraminoType() > kTetraminoEmpty) && (tetraminoInExtractedDetailsData->getTetraminoType() == kTetraminoEmpty))
			{

				vector <GamePositionOnBoard> detailElements = getDetailFromStartPosition(xIndex, yIndex);
				detailsInGameBoard.push_back(detailElements);
				setDetailsInExtractedDetailsData(detailElements, extractedDetailsData);
			}

		}

	}
	return detailsInGameBoard;
}
Пример #2
0
long MainPlayer::potentialMobilityHeuristic(const GameBoard &gameBoard, Tile tile) {
    long potentialMobility = 0;
    auto gameSize = gameBoard.getGameSize();
    auto enemyTile = gameBoard.getEnemyTile(tile);

    for (size_t row = 0; row < gameSize; ++row) {
        for (size_t column = 0; column < gameSize; ++column) {
            Cell here(row, column);
            if (gameBoard.getAt(here) != tile) {
                continue;
            }
            for (int offsetRow = -1; offsetRow < 2; ++offsetRow) {
                for (int offsetCol = -1; offsetCol < 2; ++offsetCol) {
                    if (offsetCol == 0 && offsetRow == 0) {
                        continue;
                    }
                    Direction direction(offsetRow, offsetCol);
                    auto neighbor = here;
                    neighbor.move(direction);
                    if (gameBoard.isCorrect(neighbor)
                        && gameBoard.getAt(neighbor) == enemyTile) {
                        ++potentialMobility;
                    }
                }
            }
        }
    }
    return potentialMobility;
}
Пример #3
0
GameBoard GameBoard::getNewState(GameBoard& new_state, int x, int y, int ai_turn_number){
    new_state.copyBoard(grid);
    new_state.setMovesSoFar(movesSoFar);
    new_state.makeMove(x, y);
    new_state.setAiTurn(ai_turn_number);
    return new_state;
}
Пример #4
0
GameBoard *GameBoard::addEmptyBoard( GameWorld *world, int pos )
{
  GameBoard *board = new GameBoard();
  world->addBoard( pos, board );

  ZZTThing::Player *player = new ZZTThing::Player();
  player->setBoard( board );
  player->setPos( 30, 12 );
  player->setCycle( 1 );
  ZZTEntity underEnt = ZZTEntity::createEntity( ZZTEntity::EmptySpace, 0x07 );
  player->setUnderEntity( underEnt );
  ZZTEntity playerEnt = ZZTEntity::createEntity( ZZTEntity::Player, 0x1f );
  playerEnt.setThing( player );

  board->setEntity( 30, 12, playerEnt );
  board->addThing( player );

  for ( int x = 0; x < 60; x++ ) {
    board->setEntity( x,  0, ZZTEntity::createEntity( ZZTEntity::Normal, 0x0e ) );
    board->setEntity( x, 24, ZZTEntity::createEntity( ZZTEntity::Normal, 0x0e ) );
  }
  for ( int y = 1; y < 24; y++ ) {
    board->setEntity(  0, y, ZZTEntity::createEntity( ZZTEntity::Normal, 0x0e ) );
    board->setEntity( 59, y, ZZTEntity::createEntity( ZZTEntity::Normal, 0x0e ) );
  }

  return board;
}
Пример #5
0
bool GameBoard::Solvable(std::set<unsigned int> &remSqs, Difficulty diff)
{
	// Determines whether the puzzle is currently solvable

	// If there are fewer than 10 squares remaining, assume the puzzle is solvable
	if(remSqs.size() < 10)
	{
		writetoLog(_("Solvable - less than 10 empty squares"), _("GameBoard.log"));
		return true;
	}

	// If there are more than 65 squares remaing, assume the puzzle is not solvable
	if(remSqs.size() > 65)
	{
		writetoLog(_("Not solvable -  more than 65 empty squares"), _("GameBoard.log"));
		return false;
	}

    bool solved;
    GameBoard * trying = new GameBoard();

    trying->Binit();
    trying->Copy(*this);
    solved = trying->Solve(remSqs, diff);
    delete trying;

	if(solved)
		writetoLog(_("Solvable - checked"), _("GameBoard.log"));
	else
		writetoLog(_("Not solvable - checked"), _("GameBoard.log"));
	return solved;
}
Пример #6
0
void Puzzle::pretty_print(const OutputSettings& settings) {
    GameBoard tmp = to_game_board();
    m_impl->m_board = tmp.to_string(settings);
    for (PuzzleSnapshot& snapshot_text : m_impl->m_snapshots) {
        GameSnapshot snapshot(snapshot_text.moves(), tmp.variant());
        snapshot_text.moves() = snapshot.to_string(settings);
    }
}
Пример #7
0
void GameLogic::setPlayableBoard(int index)
{
    GameBoard * currentBoard = mBoards.at(index);
    bool allBoardsPlayable = currentBoard->isFull();
    for (auto itr : mBoards) {
        itr->setPlayable(allBoardsPlayable);
    }
    currentBoard->setPlayable(true);
}
Пример #8
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    GameBoard window;
    window.setWindowTitle("Mario Game");
    window.show();
    center(window);
    return app.exec();
}
Пример #9
0
int main()
{
	GameBoard *board = new GameBoard();
	while (board->doTurn());
	delete board;
	int a;
	cin >> a;
	return 0;
}
Пример #10
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    GameBoard gameboard;
    gameboard.show();

    return app.exec();
}
Пример #11
0
int main( int argc, char** argv )
{
    QApplication app( argc, argv );

    GameBoard board;
    board.setGeometry( 100, 100, 500, 355 );
    board.show();

    return app.exec();
}
Пример #12
0
int main( int argc, char **argv )
{
    QApplication::setColorSpec( QApplication::CustomColor );
    QApplication a( argc, argv );

    GameBoard gb;
    gb.setGeometry( 100, 100, 500, 355 );
    a.setMainWidget( &gb );
    gb.show();
    return a.exec();
}
Пример #13
0
/*
    Function Name: oscillatorPattern
    Function Parameters: GameBoard instance and the x and y coordinates upon
                         which to place the shape
    What the function does: creates a new gameboard from the GameBoard instance,
                            populating it with the oscillator pattern, then
                            destroying the old board and setting the newly
                            created board as the instance's gameboard array
*/
GameBoard oscillatorPattern(GameBoard gameboard, int y, int x) {
    int p_height = 1;
    int p_width = 3;
    int** pattern = gameboard.createBoard();  // set the pattern to use the gameboard's array

    // 1st row: X X X
    pattern[y + 0][x + 0] = 1; pattern[y + 0][x + 1] = 1; pattern[y + 0][x + 2] = 1;

    gameboard.destroyBoard();
    gameboard.setBoard(pattern);
    return gameboard;
}
Пример #14
0
GamePhase MainPlayer::getGamePhase(const GameBoard &gameBoard) {
    if (gameBoard.getEmptyCount() > 44) {
        return GAME_BEGIN;
    }
    if (gameBoard.getEmptyCount() < 12) {
        return GAME_END;
    }
    if (gameBoard.getEmptyCount() < 20) {
        return GAME_PREEND;
    }
    return GAME_MIDDLE;
}
Пример #15
0
GameBoard randomBoard() {

    GameBoard board;
    for (int y = 0; y < board.size(); y++) {
        for (int x = 0; x < board.size(); x++) {
            double fval = rand() * 17;
            int value = (int) fval;
            board.setElementAt(x, y, value);
        }
    }
    return board;

}
Пример #16
0
GameLogic::GameLogic(double x, double y, double size)
:   GameGrid(x, y, size),
mActive(true),
mCurrentPlayer(0)
{
    std::vector<Square *> locations = getLocations();
    GameBoard *board;
    for (auto itr : locations) {
        board = new GameBoard(*itr);
        board->adjust(1, 1, -2);
        mBoards.push_back(board);
        delete itr;
    }
}
int main() {
	GameBoard gameboard;
	gameboard.init();

	gameboard.addPiece(new Piece('O'));

	char input = 0;
	while (true) {
		draw(gameboard);
		processInput(gameboard, _getch());
	}

	gameboard.finalize();
}
Пример #18
0
// If board array change size interface will lock bad!!!!!
void Graphics::Board() const {
	printf("\t\t-------------------------------------------------\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");
	printf("\t\t|");
	printf("\t%c", g.ReturnBoardMark(0));
	
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(1));
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(2));
	printf("\t|\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");

	printf("\t\t-------------------------------------------------\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");
	printf("\t\t|");
	printf("\t%c", g.ReturnBoardMark(3));
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(4));
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(5));
	printf("\t|\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");

	printf("\t\t-------------------------------------------------\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");
	printf("\t\t|");
	printf("\t%c", g.ReturnBoardMark(6));
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(7));
	printf("\t|");
	printf("\t%c", g.ReturnBoardMark(8));
	printf("\t|\n");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|");
	printf("\t\t|\n");
	printf("\t\t-------------------------------------------------\n");
}
Пример #19
0
bool GameBoard::Solvable()
{
	// Determines whether the puzzle is currently solvable

    bool solved;
    GameBoard * trying = new GameBoard();

    trying->Binit();
    trying->Copy(*this);
    solved = trying->Solve();
    delete trying;


	return solved;
}
Пример #20
0
long MainPlayer::mobilityHeuristic(const GameBoard &gameBoard, Tile tile) const {
    long mobility = 0;
    auto gameSize = gameBoard.getGameSize();
    for (size_t row = 0; row < gameSize; ++row) {
        for (size_t column = 0; column < gameSize; ++column) {
            Cell here(row, column);
            if (gameBoard.canPutTile(here, tile)) {
                ++mobility;
            }
        }
    }
    /*gameBoard.print(std::cerr);
    std::cerr << mobility << '\n';*/
    return mobility;
}
void processGameBoard(const GameBoard& board)
{
	const std::unique_ptr<GamePiece>& pawn = board.at(0, 0);

	// Doesn't compile
	//board.at(1, 2) = std::make_unique<ChessPiece>();
}
Пример #22
0
long MainPlayer::edgeStabilityHeuristic(const GameBoard &gameBoard, Tile tile) const {
    auto gameSize = gameBoard.getGameSize();
    std::vector<Direction> directions{{0,  1},
                                      {0,  -1},
                                      {1,  0},
                                      {-1, 0}};

    std::vector<Cell> corners{{0,            0},
                              {0,            gameSize - 1},
                              {gameSize - 1, 0},
                              {gameSize - 1, gameSize - 1}};
    auto board = gameBoard;
//    board.print(std::cerr);
    long stableCellsCount = 0;
    for (Cell corner : corners) {
        if (board.getAt(corner) != tile) {
            continue;
        }
        ++stableCellsCount;
        for (Direction direction : directions) {
            auto current = corner;
            current.move(direction);
            while (board.isCorrect(current) && board.getAt(current) == tile) {
                ++stableCellsCount;
                board.setAt(current, EMPTY);
//                board.print(std::cerr);
                current.move(direction);
            }
        }
    }
    return stableCellsCount;
}
Пример #23
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    //Create the menu and the game board.
    WizardMenuClass* w = new WizardMenuClass;
    GameBoard* b = new GameBoard;

    //Set the game board and menu so that they are connected.
    w->setGameBoard(b);
    b->setWizardmenu(w);

    w->show(); //Show the game board.

    return a.exec();
}
void processGameBoard(const GameBoard& board)
{
	const GamePiece* pawn = board.getPieceAt(0, 0);

	// Doesn't compile
	//board.setPieceAt(1, 2, pawn);
}
Пример #25
0
bool Runtime::parseConditionalAny( KILLENUM &kill )
{
  Token::Code code = tokenizer.token();
  Token::Code colorCode = Token::UNKNOWN;
  unsigned char colorCheck = 0xFF;

  // Check for color prefix first:
  switch (code)
  {
    case Token::BLUE:   colorCode = code; colorCheck = Defines::BLUE; break;
    case Token::GREEN:  colorCode = code; colorCheck = Defines::GREEN; break;
    case Token::CYAN:   colorCode = code; colorCheck = Defines::CYAN; break;
    case Token::RED:    colorCode = code; colorCheck = Defines::RED; break;
    case Token::PURPLE: colorCode = code; colorCheck = Defines::MAGENTA; break;
    case Token::YELLOW: colorCode = code; colorCheck = Defines::YELLOW; break;
    case Token::WHITE:  colorCode = code; colorCheck = Defines::WHITE; break;
    default: break;
  }

  // Get actual entity after color prefix
  if (colorCode != Token::UNKNOWN) {
    accept( colorCode );
    code = tokenizer.token();
  }

  // translate from Token code to ZZTEntity code.
  unsigned char idCheck = translateEntityToken( code );

  if ( idCheck == ZZTEntity::NONE_ENTITY ) {
    kill = throwError("CONDITIONAL ERROR");
    return false;
  }

  return board->isAnyEntity( idCheck, colorCheck );
}
Пример #26
0
/*
    Function Name: gliderPattern
    Function Parameters: GameBoard instance and the x and y coordinates upon
                         which to place the shape
    What the function does: creates a new gameboard from the GameBoard instance,
                            populating it with the glider pattern, then
                            destroying the old board and setting the newly
                            created board as the instance's gameboard array
*/
GameBoard gliderPattern(GameBoard gameboard, int y, int x) {
    int p_height = 3;
    int p_width = 3;
    int** pattern = gameboard.createBoard();  // set the pattern to use the gameboard's array
    // validate_coordinates(gameboard, p_height, p_width, y, x);

    // 1st row: _ X _
    pattern[y + 0][x + 0] = 0; pattern[y + 0][x + 1] = 1; pattern[y + 0][x + 2] = 0;
    // 2nd row: _ _ X
    pattern[y + 1][x + 0] = 0; pattern[y + 1][x + 1] = 0; pattern[y + 1][x + 2] = 1;
    // 3rd row: X X X
    pattern[y + 2][x + 0] = 1; pattern[y + 2][x + 1] = 1; pattern[y + 2][x + 2] = 1;

    gameboard.destroyBoard();
    gameboard.setBoard(pattern);
    return gameboard;
}
Пример #27
0
int main()
{
    Player p1;
    Player p2;
    GameBoard game;

    cout << "Welcome to Tic Tac Toe!" << endl;
    cout << "First Player: " << endl;
    p1.setName();
    while (!p1.setSymbol()) {
        cout << "Invalid symbol" << endl;
    }

    cout << "Second Player: " << endl;
    p2.setName();
    while (!p2.setSymbol() || p2.getSymbol() == p1.getSymbol()) {
        cout << "Invalid symbol" << endl;
    }

    game.setPlayer1(&p1);
    game.setPlayer2(&p2);

    while (!game.winner()) {
        game.nextTurn();
    }
    game.printBoard();
    cout << game.getWinner()->getName() << " is the winner!" << endl;

    return 0;
}
Пример #28
0
/**** Board methods *******/
GameBoard::GameBoard(const GameBoard &other):
    rowNum(other.getRowNumber()),
    colNum(other.getColNumber()),
    freeBoxes(other.freeBoxes),
    last_to_play(other.lastToPlay()),
    next_to_play(other.nextToPlay())
{
    game_board = new Player*[rowNum];

    for(int i = 0; i < rowNum; i++)
    {
        game_board[i] = new Player[colNum];
        for(int j = 0; j < colNum; j++)
        {
            game_board[i][j] = other.getValue(i, j);
        }
    }
}
Пример #29
0
int main(){

  GameBoard gb;
  Player p1("human",'X');
  Player p2("ai",'O');
  int row,column;
  p1.setTurn(); //its player 1s turn

  while(!done){ //game loop
    gb.Update();
    if(p1.getTurn()){
      cout<<"Player 1"<<endl;
      getMove(row,column);
      cout<< gb.Move(row,column,p1);
    }
    gb.Update();
  }
}
Пример #30
0
GameBoard::GameBoard( GameBoard const &b ){
  setupBoard();

  for ( int i=0; i<_rows; i++) {
    for ( int j=0; j<_columns; j++) {
      markSquare( j, i, b.getSquare( j, i ) );
    }
  }

}