-
Notifications
You must be signed in to change notification settings - Fork 0
/
Play Move.h
118 lines (97 loc) · 2.43 KB
/
Play Move.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
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
//
// Make Move.h
// Cmd Line Chess AI
//
// Created by Robert Lewis on 6/12/21.
// Copyright © 2021 Robert Lewis. All rights reserved.
//
#include "Generate Moves.h"
std::array<piece, 64> makeMove(std::array<piece, 64> oldBoard, int colourToMove, int move) {
std::array<piece, 64> newBoard;
int origin = floor((move % 10000) / 100);
int destination = move % 100;
int special = floor(move / 10000);
piece movedPiece = oldBoard[origin];
movedPiece.location = destination;
movedPiece.move2 = false;
movedPiece.castle = false;
for (int i = 0; i < 64; i ++) {
piece blankPiece(' ', i);
if (i == origin) {
newBoard[i] = blankPiece;
}
else if (i == destination) {
newBoard[i] = movedPiece;
}
else {
newBoard[i] = oldBoard[i];
}
}
if (special != 0) {
if (special == 1) {
//Castle Kingside
newBoard[destination + 1].castle = false;
newBoard[destination - 1] = newBoard[destination + 1];
piece blankPiece(' ', destination + 1);
newBoard[destination + 1] = blankPiece;
}
else if (special == 2) {
//Castle Queenside
newBoard[destination - 2].castle = false;
newBoard[destination + 1] = newBoard[destination - 2];
piece blankPiece(' ', destination - 2);
newBoard[destination - 2] = blankPiece;
}
else if (special == 3) {
//En Passant
piece blankPiece(' ', destination - 8 * colourToMove);
newBoard[destination - 8 * colourToMove] = blankPiece;
}
else if (special == 4) {
//Move 2
newBoard[destination].move2 = false;
newBoard[destination].enPassant = true;
}
else if (special == 5) {
//Promote To Queen
if (colourToMove == 1) {
piece queen('Q', destination);
newBoard[destination] = queen;
}
else {
piece queen('q', destination);
newBoard[destination] = queen;
}
}
}
//Disable EnPassant
int begin = 28 + 4 * colourToMove;
for (int i = 0; i < 8; i ++) {
newBoard[begin + i].enPassant = false;
}
return newBoard;
}
int playerMove(std::vector<int> moveList) {
bool allowedMove = false;
int move = 0;
while (!allowedMove) {
std::cout << "You play: ";
std::cin >> move;
if (move == 0) {
for (int i = 0; i < moveList.size(); i ++){
std::cout << moveList[i] << std::endl;
}
}
else {
for (int i = 0; i < moveList.size(); i ++){
if (moveList[i] == move) {
allowedMove = true;
break;
}
}
if (!allowedMove) std::cout << "Move not in Move List" << std::endl;
}
}
return move;
}
/* Make_Move_h */