summaryrefslogtreecommitdiff
path: root/move.cpp
blob: 70c7610bff3cec5bd313024759e664af2b922aae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cassert>
#include "move.h"


Move::Move(const char *str) {
	if (str[0] >= 'a' && str[0] <= 'h' &&
			str[1] >= '1' && str[1] <= '8' &&
			str[2] >= 'a' && str[2] <= 'h' &&
			str[3] >= '1' && str[3] <= '8' &&
			str[4] == '\0') {
		from = 8 * ('8' - str[1]) + str[0] - 'a';
		to = 8 * ('8' - str[3]) + str[2] - 'a';
		castle = 0;
	} else if (strcmp(str, "O-O") == 0) {
		castle = 1;
	} else if (strcmp(str, "O-O-O") == 0) {
		castle = -1;
	} else {
		throw std::runtime_error("Invalid Move string");
	}
}