资源简介
围棋
代码片段和文件信息
#include
#include
#include
#include
#include “board.h“
void Board::Clear()
{
std::vector().swap(Tree);
std::vector().swap(Tree2);
Node node;
node.Turn = BLACK;
node.Pass = 0;
Tree.push_back(node);
Turn = BLACK;
Mode = 3; // play black and white
Index = 0;
Index2 = -1;
Path = 0;
Pass = 0;
memset(Point 0 sizeof(Point));
memset(Mark 0 sizeof(Point));
memset(Area 0 sizeof(Point));
}
void Board::Reset(int x int y)
{
if (x > MAX_BOARD) x = MAX_BOARD;
else if (x < MIN_BOARD) x = MIN_BOARD;
if (y > MAX_BOARD) y = MAX_BOARD;
else if (y < MIN_BOARD) y = MIN_BOARD;
Size = Width = x;
Height = y;
int a = 3;
int b = Size - 4;
int c = (Size - 1) / 2;
Star[0] = a; Star[1] = a;
Star[2] = b; Star[3] = a;
Star[4] = a; Star[5] = b;
Star[6] = b; Star[7] = b;
Star[8] = c; Star[9] = c;
Star[10] = c; Star[11] = a;
Star[12] = a; Star[13] = c;
Star[14] = b; Star[15] = c;
Star[16] = c; Star[17] = b;
Clear();
}
int Board::CheckBound(int x int y)
{
return (x >= 0 && y >= 0 && x < Width && y < Height);
}
int Board::GetColor(int x int y)
{
return Point[y][x];
}
void Board::Print()
{
char Color[3] = {‘.‘ ‘X‘ ‘O‘};
for (int y = 0; y < Height; y++) {
for (int x = 0; x < Width; x++) {
printf(“%c “ Color[GetColor(x y)]);
}
printf(“\n“);
}
printf(“\n“);
}
int Board::OtherColor(int color)
{
return (color ^ 3);
}
Board::Property Board::MakeProperty(int label int value int x int y)
{
Property Prop;
Prop.Label = label;
Prop.Value = value;
Prop.Row = x;
Prop.Col = y;
return Prop;
}
void Board::Capture(int x int y int color Node *n)
{
if (CheckBound(x y) && GetColor(x y) == color) {
Point[y][x] = 0;
n->Prop.push_back(MakeProperty(TOKEN_TAKE color x y));
Capture(x - 1 y color n);
Capture(x + 1 y color n);
Capture(x y - 1 color n);
Capture(x y + 1 color n);
}
}
int Board::CheckLiberty(int x int y int color)
{
if (CheckBound(x y))
{
int k = GetColor(x y);
if (k == EMPTY) return 1;
if (k != color || Mark[y][x] == Path) return 0;
// visit //
Mark[y][x] = Path;
// found liberty //
if (CheckLiberty(x - 1 y color)) return 1;
if (CheckLiberty(x + 1 y color)) return 1;
if (CheckLiberty(x y - 1 color)) return 1;
if (CheckLiberty(x y + 1 color)) return 1;
}
return 0;
}
// check for capture //
void Board::Check(int x int y int color Node *node)
{
if (CheckBound(x y) && GetColor(x y) == color) {
Path = Path + 1;
if (CheckLiberty(x y color) == 0)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-04-08 17:26 Board-master\
文件 40211 2016-04-08 17:26 Board-master\A01.png
文件 65597 2016-04-08 17:26 Board-master\A02.png
文件 68000 2016-04-08 17:26 Board-master\A03.png
文件 1513 2016-04-08 17:26 Board-master\README.md
目录 0 2016-04-08 17:26 Board-master\Release\
文件 41 2016-04-08 17:26 Board-master\Release\Beta.bat
文件 184320 2016-04-08 17:26 Board-master\Release\Beta.exe
文件 17375232 2016-04-08 17:26 Board-master\Release\board.exe
文件 13440 2016-04-08 17:26 Board-master\board.cpp
文件 2279 2016-04-08 17:26 Board-master\board.h
文件 119 2016-04-08 17:26 Board-master\board.pro
文件 61 2016-04-08 17:26 Board-master\board.rc
文件 4286 2016-04-08 17:26 Board-master\favicon.ico
文件 20060 2016-04-08 17:26 Board-master\window.cpp
文件 1479 2016-04-08 17:26 Board-master\window.h
评论
共有 条评论