Skip to content

Commit

Permalink
Add skeleton for board class
Browse files Browse the repository at this point in the history
  • Loading branch information
dark committed Jan 27, 2024
1 parent 6055ece commit 3777bd7
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ project(skyscraper-puzzle
HOMEPAGE_URL "https://github.com/dark/skyscraper-puzzle"
LANGUAGES CXX)

add_executable(skyscraper main.cc)
add_executable(skyscraper
board.cc
main.cc)
35 changes: 35 additions & 0 deletions board.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Generate and solve skyscraper puzzles
* Copyright (C) 2024 Marco Leogrande
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "board.h"

#include <cstdlib>
#include <iostream>

Board::Board(const int size)
: size_(size) {
if (size <= 0) {
std::cerr << "Bad board size: " << size << std::endl;
std::abort();
}

board_.resize(size);
for (int i = 0; i < size; ++i) {
board_[i].resize(size);
}
}
35 changes: 35 additions & 0 deletions board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Generate and solve skyscraper puzzles
* Copyright (C) 2024 Marco Leogrande
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef BOARD_H
#define BOARD_H

#include <vector>

class Board {
public:
explicit Board(const int size);

private:
const int size_;

// Each inner vector is a row, and the outer vector selects the row.
std::vector<std::vector<int>> board_;
};

#endif
3 changes: 3 additions & 0 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "board.h"

int main(void) {
Board b{5};
return 0;
}

0 comments on commit 3777bd7

Please sign in to comment.