-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chessboard.cpp
105 lines (102 loc) · 2.19 KB
/
Chessboard.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
#include "ChessBoard.h"
#include "Game.h"
#include<iostream>
//按照计算机存储的getof
int ChessBoard::getof(int x, int y)
{
return qp[x][y];
}
//按照棋盘逻辑的getof
int ChessBoard::getof(Point p)
{
return qp[16 - p.getY()][p.getX()];
}
//按照计算机存储的setof
bool ChessBoard::setof(int x, int y, int value)
{
if (x < 0 || x > 17 || y < 0 || y > 17)
{
return false;
}
qp[x][y] = value;
return true;
}
//按照棋盘逻辑的setof
bool ChessBoard::setof(Point p, int value)
{
int x = p.getX();
int y = p.getY();
if (x < 1 || x > 15 || y < 1 || y > 15)
{
return false;
}
qp[16 - y][x] = value;
return true;
}
int ** ChessBoard::getQp()
{
return qp;
}
ChessBoard::ChessBoard() {
qp = new int* [17];
for (int i = 0; i < 17; i++)qp[i] = new int[17];
for (int i = 0; i < 17; i++)
for (int j = 0; j < 17; j++)
qp[i][j] = 0;
}
ChessBoard::~ChessBoard() {
}
int ChessBoard::out(int i,int j,int **p)
{
if (p[i][j] == 1)return printf("●");
if (p[i][j] == 2)return printf("○");
if (p[i][j] == -1)return printf("▲");
if (p[i][j] == -2)return printf("△");
if (i == 15)
{
if (j == 1)return printf("┏");
if (j == 15)return printf("┓");
return printf("┯");
}
if (i == 1)
{
if (j == 1)return printf("┗");
if (j == 15)return printf("┛");
return printf("┷");
}
if (j == 1)return printf("┠");
if (j == 15)return printf("┨");
return printf("┼");
}
void ChessBoard::DrawBoard(int **p)//画棋盘
{
system("cls");
int row = 0, col = 0, keyr = 0, keyc = 0;
char alpha = 'A';
printf("\n\n\n ");
for (col = 1; col <= 15; col++)printf("%c ", alpha++);
for (row = 15; row >= 1; row--)
{
printf("\n %2d", row);
for (col = 1; col <= 15; col++)
{
out(row, col,p);
if (p[row][col] < 0)keyr = row, keyc = col;
}
printf("%d", row);
}
alpha = 'A';
printf("\n ");
for (col = 1; col <= 15; col++)printf("%c ", alpha++);
printf("\n\n");
if (Game::getGameModel()==1) {
if (Game::getIsFirst() == 1)printf(" player1执黑,player2执白\n");
else printf(" player1执白,player2执黑\n");
}
else {
if (Game::getIsFirst() ==2)printf(" AI执黑,玩家执白\n");
else printf(" AI执白,玩家执黑\n");
}
alpha = 'A';
if (keyr)printf(" 最后落子位置:%c%d\n", alpha + keyc - 1, keyr);
}