about summary refs log tree commit diff stats
path: root/Source/Puzzle.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2019-11-16 10:27:06 -0800
committerjbzdarkid <jbzdarkid@gmail.com>2019-11-16 10:27:06 -0800
commit0baa521ba34d2cd4e0f732f83d23b807605786a2 (patch)
treedfb01163d291ee846c7a5840ffc08e089a7fb8e6 /Source/Puzzle.cpp
parent0d0abe2ee56382c5751dd12fbca75af87773879f (diff)
downloadwitness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.tar.gz
witness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.tar.bz2
witness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.zip
More and more progress.
Split out functions in serializer
Figured out how to allocate memory (for sequences)
Diffstat (limited to 'Source/Puzzle.cpp')
-rw-r--r--Source/Puzzle.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/Source/Puzzle.cpp b/Source/Puzzle.cpp index 72af129..d0ede27 100644 --- a/Source/Puzzle.cpp +++ b/Source/Puzzle.cpp
@@ -2,18 +2,17 @@
2#include "Memory.h" 2#include "Memory.h"
3#include <cassert> 3#include <cassert>
4 4
5 5Cell Puzzle::GetCell(int x, int y) const {
6inline Cell Puzzle::GetCell(int x, int y) const {
7 x = Mod(x); 6 x = Mod(x);
8 if (!SafeCell(x, y)) return Cell::Undefined(); 7 if (!SafeCell(x, y)) return Cell::Undefined();
9 return grid[x][y]; 8 return grid[x][y];
10} 9}
11 10
12inline Cell::Color Puzzle::GetLine(int x, int y) const { 11Cell::Color Puzzle::GetLine(int x, int y) const {
13 return grid[x][y].color; 12 return grid[x][y].color;
14} 13}
15 14
16inline void Puzzle::NewGrid(int newWidth, int newHeight) { 15void Puzzle::NewGrid(int newWidth, int newHeight) {
17 if (newWidth == 0) { 16 if (newWidth == 0) {
18 assert(false); 17 assert(false);
19 newWidth = width; 18 newWidth = width;
@@ -28,12 +27,12 @@ inline void Puzzle::NewGrid(int newWidth, int newHeight) {
28 for (int x=0; x<width; x++) grid[x].resize(height); 27 for (int x=0; x<width; x++) grid[x].resize(height);
29} 28}
30 29
31inline int Puzzle::Mod(int x) const { 30int Puzzle::Mod(int x) const {
32 if (!pillar) return x; 31 if (!pillar) return x;
33 return (x + width * height * 2) % width; 32 return (x + width * height * 2) % width;
34} 33}
35 34
36inline bool Puzzle::SafeCell(int x, int y) const { 35bool Puzzle::SafeCell(int x, int y) const {
37 if (x < 0 || x >= width) return false; 36 if (x < 0 || x >= width) return false;
38 if (y < 0 || y >= height) return false; 37 if (y < 0 || y >= height) return false;
39 return true; 38 return true;