If (chess_num <= 1)
{
Srand((unsigned)time(NULL));
Do
{
Row1 = rand() % 2 + 6;
Col1 = rand() % 2 + 6;
} while (!judge(row1, col1));
Chess_piece(row1, col1);
}
Else
{
For (I = 0; I < N; i++)
{
For (j = 0; j < N; j++)
{
If (judge(I, j))
{
Cscorel = chessscore(I, j, p1);
If (cscorel > cscore)
{
Cscore = cscorel;
Row1 = I;
Col1 = j;
}
Pscorel = chessscore(I, j, p2);
If (pscorel > pscore)
{
Pscore = pscorel;
Row2 = I;
Col2 = j;
}
}
}
}
If (row1 == -1 && col1 == -1 && row2 == -1 && col2 == -1)//没找到最优解 平局
{
Msg_restart(2);
}
Else
{
If (chess_num == 3)
{
Chess_piece(row2, col2);
}
Else
{
If (cscore > pscore)
{
Chess_piece(row1, col1);
}
Else
{
Chess_piece(row2, col2);
}
}
}
}
}
Void Mouse()//鼠标移动
{
If (param == player_player)
{
If (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
Switch (msg.uMsg)
{
Case WM_LBUTTONDOWN://左键按下
Int x1 = mod_xy(msg.x);
Int y1 = mod_xy(msg.y);
Chess_piece(x1, y1);
Break;
}
}
}
Else
{
If (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
Switch (msg.uMsg)
{
Case WM_LBUTTONDOWN://左键按下
Int x1 = mod_xy(msg.x);
Int y1 = mod_xy(msg.y);
If (Chess_piece(x1, y1))
{
Chesscomputer();
}
Break;
}
}
}
}
Void Start_Game()
{
Initgraph(width, heigth);//初始化窗口
Setbkcolor(RGB(249,214,91));//设置背景色
Cleardevice();
Draw_checkboard();
Oninit();
Int res = MessageBoxA(0, “人机模式”, “模式”, MB_YESNO | MB_SYSTEMMODAL);
If (res==IDYES)
{
Param = player_AI;
}
Else
{
Param = player_player;
}
}
Void restart()
{
Oninit();
Cleardevice();
Draw_checkboard();
While (1)
{
//chesscomputer();
Mouse();
}
}
Void exitgame()
{
Closegraph();
Exit(0);
}
Void main()
{
Start_Game();
While (1)
{
Mouse();
}
}
If (chess_num <= 1)
{
Srand((unsigned)time(NULL));
Do
{
Row1 = rand() % 2 + 6;
Col1 = rand() % 2 + 6;
} while (!judge(row1, col1));
Chess_piece(row1, col1);
}
Else
{
For (I = 0; I < N; i++)
{
For (j = 0; j < N; j++)
{
If (judge(I, j))
{
Cscorel = chessscore(I, j, p1);
If (cscorel > cscore)
{
Cscore = cscorel;
Row1 = I;
Col1 = j;
}
Pscorel = chessscore(I, j, p2);
If (pscorel > pscore)
{
Pscore = pscorel;
Row2 = I;
Col2 = j;
}
}
}
}
If (row1 == -1 && col1 == -1 && row2 == -1 && col2 == -1)//没找到最优解 平局
{
Msg_restart(2);
}
Else
{
If (chess_num == 3)
{
Chess_piece(row2, col2);
}
Else
{
If (cscore > pscore)
{
Chess_piece(row1, col1);
}
Else
{
Chess_piece(row2, col2);
}
}
}
}
}
Void Mouse()//鼠标移动
{
If (param == player_player)
{
If (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
Switch (msg.uMsg)
{
Case WM_LBUTTONDOWN://左键按下
Int x1 = mod_xy(msg.x);
Int y1 = mod_xy(msg.y);
Chess_piece(x1, y1);
Break;
}
}
}
Else
{
If (MouseHit())
{
MOUSEMSG msg = GetMouseMsg();
Switch (msg.uMsg)
{
Case WM_LBUTTONDOWN://左键按下
Int x1 = mod_xy(msg.x);
Int y1 = mod_xy(msg.y);
If (Chess_piece(x1, y1))
{
Chesscomputer();
}
Break;
}
}
}
}
Void Start_Game()
{
Initgraph(width, heigth);//初始化窗口
Setbkcolor(RGB(249,214,91));//设置背景色
Cleardevice();
Draw_checkboard();
Oninit();
Int res = MessageBoxA(0, “人机模式”, “模式”, MB_YESNO | MB_SYSTEMMODAL);
If (res==IDYES)
{
Param = player_AI;
}
Else
{
Param = player_player;
}
}
Void restart()
{
Oninit();
Cleardevice();
Draw_checkboard();
While (1)
{
//chesscomputer();
Mouse();
}
}
Void exitgame()
{
Closegraph();
Exit(0);
}
Void main()
{
Start_Game();
While (1)
{
Mouse();
}
}