Permalink
Browse files

Implement the very basic board representation.

  • Loading branch information...
1 parent 0563f9b commit 5612a0e4f33cb8abb5da5706952d315a117c73d0 @crazy-eddie committed Nov 15, 2014
Showing with 63 additions and 10 deletions.
  1. +30 −0 include/board.hpp
  2. +2 −2 test/unit/CMakeLists.txt
  3. +0 −8 test/unit/blah.cpp
  4. +31 −0 test/unit/board.cpp
View
@@ -0,0 +1,30 @@
+#ifndef BOARD_HPP
+#define BOARD_HPP
+
+#include <array>
+
+namespace crazychess
+{
+
+enum struct piece
+{
+ empty = 0
+ , white_pawn
+ , white_rook
+ , white_knight
+ , white_bishop
+ , white_queen
+ , white_king
+ , black_pawn
+ , black_rook
+ , black_bishop
+ , black_queen
+ , black_king
+};
+using pieces = piece;
+
+using board = std::array<piece, 64>;
+
+}
+
+#endif
@@ -4,7 +4,7 @@ find_package(Boost COMPONENTS unit_test_framework)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
add_custom_target(tests)
-include_directories(${Boost_INCLUDE_DIR})
+include_directories(${Boost_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include)
function(add_boost_test name)
add_executable(${name} EXCLUDE_FROM_ALL ${ARGN})
@@ -17,4 +17,4 @@ function(add_boost_test name)
add_dependencies(tests ${name})
endfunction()
-add_boost_test(blah blah.cpp)
+add_boost_test(board_test board.cpp)
View
@@ -1,8 +0,0 @@
-#define BOOST_TEST_DYN_LINK
-#define BOOST_TEST_MODULE blah
-#include <boost/test/unit_test.hpp>
-
-
-BOOST_AUTO_TEST_CASE(derp)
-{
-}
View
@@ -0,0 +1,31 @@
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE board
+#include <boost/test/unit_test.hpp>
+
+#include <board.hpp>
+
+BOOST_AUTO_TEST_CASE(empty_board)
+{
+ auto board = crazychess::board{};
+
+ for (auto const& space : board)
+ {
+ BOOST_CHECK(space == crazychess::pieces::empty);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(occupied_spaces)
+{
+ auto board = crazychess::board{};
+
+ board[0] = crazychess::pieces::white_pawn;
+ board[1] = crazychess::pieces::black_king;
+ board[2] = crazychess::pieces::white_rook;
+
+ BOOST_CHECK(board[0] == crazychess::pieces::white_pawn);
+ BOOST_CHECK(board[1] == crazychess::pieces::black_king);
+ BOOST_CHECK(board[2] == crazychess::pieces::white_rook);
+
+ std::for_each( std::begin(board)+3, std::end(board)
+ , [](crazychess::piece p) { BOOST_CHECK(p == crazychess::pieces::empty); });
+}

0 comments on commit 5612a0e

Please sign in to comment.