📄 makemove.c
字号:
//makemove.c
#include <assert.h>
#include "data.h"
#include "utility.h"
//生成新局面
int MakeMove(int piece, int to)
{
int tmp = stoneIntersection[piece];
#ifdef _DEBUG
//合法性检查
int i = 0;
assert((0 <= (to&15)) && ((to&15) <= 9));
for(i = 0; i < 3; ++i)
assert(to ==stoneIntersection[i]);
#endif
stoneIntersection[piece] = to;
return tmp;
}
//撤销局面
void UnmakeMove(int piece, int from)
{
#ifdef _DEBUG
assert((0 <= (from&15)) && ((from&15) <= 9));
#endif
stoneIntersection[piece] = from;
}
//将着法字符串-->着法的内部表示
int InputMove(char *buf, int wtm)
{
int i;
int from, to;
int rVal = 1;
//str_to_ascii
from = buf[0] - '0';
to = buf[1] - '0';
//非法着法,返回继续等待输入的状态
if((from < 0) || (from > 9))
return 1;
if((to < 0) || (to > 9))
return 1;
if( RED == wtm &&
(from != stoneIntersection[REDSTONE] ||
to == stoneIntersection[BLUESTONE1] ||
to == stoneIntersection[BLUESTONE2] ))
return 1;
else if(BLUE == wtm &&
((from != stoneIntersection[BLUESTONE1] &&
from != stoneIntersection[BLUESTONE2])
|| to == stoneIntersection[REDSTONE]
|| to == stoneIntersection[BLUESTONE1]
|| to == stoneIntersection[BLUESTONE2]))
return 1;
if(2 < abs(from - to))
return 1;
//合法着法
for(i = 0; i < 3; ++i)
{
if(from == stoneIntersection[i])
{
stoneIntersection[i] = to;
rVal = -1;
}
}
if(traceOut)
{
Trace_board(stoneIntersection);
traceOut = 0;
}
return rVal;
}
//着法内部表示-->输出字符串
void OutputMove(int move)
{
int i;
int piece, from, to;
char buf[4];
piece = (move & 48) >> 4;
to = move & 15;
//ascii_to_str
buf[0] = stoneIntersection[piece] + '0'; //from
buf[1] = to + '0'; //to
buf[2] = '\0'; //'\0'
Print("Computer: %s\n", buf);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -