-
Notifications
You must be signed in to change notification settings - Fork 0
/
procon26_modio.cpp
134 lines (121 loc) · 2.73 KB
/
procon26_modio.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "Procon26_modio.hpp"
#include <iostream>
#include <fstream>
using namespace std;
/* Implementation */
Stone *getStoneByString(string stone)
{
Stone *returnStone = new Stone;
for (int y = 0; y < STONE_SIZE; y++)
{
returnStone->zuku[y] = 0;
for (int x = 0; x < STONE_SIZE; x++)
{
char c = stone[x + y * STONE_SIZE];
if (c == '1')
{
returnStone->zuku[y] += (0x80 >> x);
}
}
}
return returnStone;
}
Board *getBoardByString(string board)
{
Board *returnBoard = new Board;
for (int y = 0; y < BOARD_SIZE; y++)
{
for (int i = 0; i < 4; i++)
{
returnBoard->block[i + y * 4] = 0;
for (int x = 0; x < 8; x++)
{
char c = board[x + 8 * i + y * BOARD_SIZE];
if (c == '1')
{
returnBoard->block[i + y * 4] += (0x80 >> x);
}
}
}
}
return returnBoard;
}
void showStone(const Stone *stone)
{
for (int y = 0; y < STONE_SIZE; y++)
{
for (int x = 0; x < STONE_SIZE; x++)
{
cout << (((stone -> zuku[y] << x) & 0x80) ? block_1 : block_0);
}
cout << endl;
}
cout << endl;
}
void showBoard(const Board *board)
{
for (int y = 0; y < BOARD_SIZE ; y++)
{
for (int i = 0; i < 4; i++)
{
for (int x = 0; x < 8; x++)
{
cout << (((board -> block[i + y * 4] << x) & 0x80) ? block_1 : block_0);
}
}
cout << endl;
}
cout << endl;
}
void inputBoard(Board *board)
{
string data = "";
for (int i = 0; i < BOARD_SIZE; i++)
{
string str;
cin >> str;
data += str;
}
*board = *getBoardByString(data);
}
void inputStone(Stone *stones, int n)
{
for (int i = 0; i < n; i++)
{
string data = "";
for (int j = 0; j < STONE_SIZE; j++)
{
string str;
cin >> str;
data += str;
}
stones[i] = *getStoneByString(data);
}
}
Problem *readProblem(string filePath)
{
Problem *ret = new Problem;
ifstream ifs(filePath.c_str());
string data = "";
for (int i = 0; i < BOARD_SIZE; i++)
{
string str;
ifs >> str;
data += str;
}
ret->board = *getBoardByString(data);
ifs >> ret->num;
ret->stones = new Stone[ret->num];
for (int i = 0; i < ret->num; i++)
{
data = "";
for (int j = 0; j < STONE_SIZE; j++)
{
string str;
ifs >> str;
data += str;
}
ret->stones[i] = *getStoneByString(data);
}
return ret;
}