-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.h
75 lines (59 loc) · 1.6 KB
/
Board.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// Board.h
//
//
// Created by Chris Vanderloo on 4/1/18.
//
#ifndef Board_h
#define Board_h
#include <stdio.h>
#include <unordered_map>
class Board {
public:
// CONSTRUCTORS
Board();
Board(Board &b);
Board(uint64_t _state, long _gScore=0) : state(_state), gameScore(_gScore) {}
// PRINTING
void printBoard();
void printNumHelper(int tile);
// MOVES
void setFirstMove();
bool move(int i, bool addTile=true, bool debug=true);
bool createRandomTile();
uint16_t smushInDirection(uint16_t val, bool pos, bool score=true);
// GETTERS
uint8_t getTile(int i);
uint16_t getCol(int i);
uint16_t getRow(int i);
// SETTERS
void setTile(int index, int value);
void setCol(int i, uint16_t v);
void setRow(int i, uint16_t v);
// SCORE
double calculateScore(bool debug=true);
/** VARIABLES **/
uint64_t state; // board state
long gameScore; // score
};
class TranspositionTable {
public:
TranspositionTable() {}
void insert(uint64_t state, double score) { table[state] = score; }
// GET
// Score returns in score variable
// RETURN: Success of retrieval from table
bool get(uint64_t state, double& score){
std::unordered_map<uint64_t, double>::iterator i = table.find(state);
if (i == table.end()) return false;
score = i->second;
return true;
}
double operator[](uint64_t state) {
return table[state];
}
std::unordered_map<uint64_t, double> table;
};
bool canMove(Board& b);
float blankTiles(Board& b);
#endif