请问这样一个游戏剩余的代码该怎么完成,现在已经完成了主函数部分:石头游戏是由两堆石头和两个玩家一起玩的。在轮到她的时候,一个玩家从较大的石头堆中取出一些石头。她取出的石头数量必须是小堆中石头数量的正倍。例如,让有序对(6,14)描述一个配置,在较小的堆中有6个石头,在较大的堆中有14个石头,然后第一个玩家可以从较大的堆中移除6或12块石头。从一堆石头中取出所有石头的玩家将赢得比赛。你的任务是用C代码编写3个函数,这样用户就可以对抗电脑了。当两名玩家中的一名获胜时,代码将显示谁获胜并退出。
#include <stdio.h>
int main(void)
{
int pile1, pile2;
int move1, move2;
printf("Input number of stones in pile 1: ");
scanf("%i",&pile1);
printf("Input number of stones in pile 2: ");
scanf("%i",&pile2);
// display piles
printf("Current piles (%i,%i)\n",pile1,pile2);
while (1) {
// ask user input
// determine if input is feasible
// repeat asking for input until move is feasible
do {
printf("Player 1 (user): How many stones do
you want to move from
the largest pile?\n");
scanf("%i",&move1);
} while (!feasible(pile1,pile2,move1));
// perform move
if (pile1<pile2) {
pile2 = pile2-move1;
pile1 = pile1+move1;
}else {
pile2 = pile2+move1;
pile1 = pile1-move1;
}
// display new piles
printf("Current piles (%i,%i)\n",pile1,pile2);
if (win(pile1,pile2)) {
printf("You win!\n");// user is the winner!
break;
}
// compute computer move
move2 = computer(pile1,pile2);
printf("Computer moves %i stones from the largest
pile\n",move2);
// perform move
if (pile1<pile2) {
pile2 = pile2-move2;
pile1 = pile1+move2;
}else {
pile2 = pile2+move2;
pile1 = pile1-move2;
}
// display new piles
printf("Current piles (%i,%i)\n",pile1,pile2);
if (win(pile1,pile2)) {
printf("The computer wins!\n");// computer is the
winner!
break;
}
}
return 0;
}