This repository was archived by the owner on Nov 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.cpp
More file actions
61 lines (54 loc) · 1.38 KB
/
Board.cpp
File metadata and controls
61 lines (54 loc) · 1.38 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
//
// Created by coope on 3/16/2021.
//
#include "Board.h"
Board::Board() {
for(int i=0;i<SIZE;i++) {
for(int j=0;j<SIZE;j++) {
if(i<3 && (i+j)%2==1) {
gameBoard[i][j] = Piece(2);
}
else if (i>4 && (i+j)%2==1) {
gameBoard[i][j] = Piece(1);
}
else {
gameBoard[i][j] = Piece();
}
}
}
}
void Board::printBoard() {
for(auto & i : gameBoard) {
printf("|");
for(auto & j : i) {
printf("%d%c|", j.player, j.name);
}
printf("\n");
}
}
bool Board::move(std::string yourMove, int player) {
int i = (int) yourMove[0] - '0';
int j = (int) yourMove[1] - '0';
int x = (int) yourMove[3] - '0';
int y = (int) yourMove[4] - '0';
if(gameBoard[x][y].name != '0' || gameBoard[i][j].name == '0') {
puts("invalid move\n");
return false;
}
if((x+y)%2==0) {
puts("invalid move\n");
return false;
}
if (gameBoard[i][j].player == player) {
Piece piece = gameBoard[i][j];
gameBoard[x][y] = piece;
gameBoard[i][j] = Piece();
puts("Moving...\n");
printBoard();
return true;
}
else {
puts("This is not your piece!\n");
return false;
}
}