-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvrcface.cpp
More file actions
65 lines (58 loc) · 1.58 KB
/
vrcface.cpp
File metadata and controls
65 lines (58 loc) · 1.58 KB
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
#include "vrcface.h"
VRCFace::VRCFace(uint size, Side side)
{
_initialSide = side;
_size = size;
_arraySize = _size * _size;
_pieces = new Piece[_arraySize];
for(uint i = 0; i < _arraySize; i++)
{
_pieces[i]._side = side;
_pieces[i]._initialSide = side;
_pieces[i]._initialPosition = i;
}
}
double VRCFace::getCost()
{
double cost = 0;
for(uint row = 0; row < _size; row++)
{
for(uint col = 0; col < _size; col++)
{
uint position = getPosition(row, col);
if(_pieces[position]._initialSide != _pieces[position]._side)
cost += 1.0;
else if(_pieces[position]._initialPosition != position)
cost += 0.5;
}
}
return cost;
}
void VRCFace::rotate(VRCAction::Rotation rotation)
{
auto buffer = new Side[_arraySize];
for(uint i = 0; i < _arraySize; i++)
{
buffer[i] = _pieces[i]._side;
}
for(uint row = 0; row < _size; row++)
{
for(uint col = 0; col < _size; col++)
{
_pieces[getPosition(row, col)].setSide(buffer[getPosition(row, col, rotation)]);
}
}
delete[] buffer;
}
uint VRCFace::getPosition(uint row, uint col, VRCAction::Rotation rotation) const
{
switch(rotation)
{
case VRCAction::Rotation::Clockwise:
return getPosition(col, _size - row - 1);
case VRCAction::Rotation::CounterClockwise:
return getPosition(_size - col - 1, row);
case VRCAction::Rotation::Turn180:
return getPosition(_size - row - 1, _size - col - 1);
}
}