c语言井字棋程序设计报告,C语言编写的井字棋.doc

C语言编写的井字棋.doc

井字旗 C 语言程序运行环境Turbo C/Cfor Windows 集成实验与学习环境或 VC6.0define MAX 3define Status intdefine HUMAN_WIN 0 人取得了胜利define DRAW 1 平局define PLAYING 2 没有决出胜负,正在 进行游 戏define COMPUTER_WIN 3 电脑取得了胜利define HUMAN 0 人define COMPUTER 1 机器define EMPTY 2 空define FALSE 0 假define TRUE 1 真include include “malloc.h“记录一步棋所需的所有信息行数,列数,判断值typedef structint column;int row;int val;Nodes;int boardMAXMAX;InitBoard初始化棋 盘Status InitBoardint row,column;forrow0; row MAX return TRUE;判断一列for column 0; column MAX return TRUE;判断主对角线if board 1 1 side 判断副对角线if board 0 2 side return FALSE;PositonValue返回落子后的状态 有四种状态在ConstNum.h中定义 COMPUTER_WIN, HUMAN_WIN, DRAW, PLAYINGStatus PostionValuereturn IsWinCOMPUTERCOMPUTER_WINIsWinHUMANHUMAN_WINBoardIsFullDRAWPLAYING;BestMovement判断最佳落子位置,采用递归 ,求出最佳位置Nodes BestMovementint sideint opp;对手Nodes nodes, node2; nodes记录当前最佳位置,node2 返回最佳位置int simple; 记 当中间结果int bestRow0, row;int bestColumn0, column;int value;判断是否游戏己经结束if simplePostionValue PLAYINGnode2.row0;node2.column0;node2.valsimple;return node2;ifsideCOMPUTERoppHUMAN;valueHUMAN_WIN;elseoppCOMPUTER;valueCOMPUTER_WIN;forrow0; row value sideHUMAN /*the pionted location is not empty*/ifchessboardrowcolNONEreturn FALSE;/*okay, put down the chess man*/chessboardrowcolplayer;return TRUE;/*check whetch the player win the game*/int chk_winnerint playerint i,j;int col,row,inc;/*are there all the players chess men in the same row*/fori0;ichess_valueicuri;/*my best is my competitors worst*/best_chess-rowchesscur.row;best_chess-colchesscur.col;return chess_valuecur;int chk_fullvoidint i,j;fori0;i row “;scanf“d“,printf“ location col “;scanf“d“,ifenter_chess_manrow-1,col-1,playerTRUEprintf“ You have take chess man at ddn“,row,col;break;elseprintf“ Error You put the chess to a wrong locationn“;whileTRUE;else/*computer says it is my turn.*/get_best_chessenter_chess_manbest_chess.row,best_chess.col,player;printf“ Player d put chess at ddn“,player,best_chess.row1,best_chess.col1;/*display the current chess board*/disp_chess_board;/*anybody win*/bENDTRUE;ifchk_winnerplayerprintf“ Player d Win the Game.n“,player;else ifchk_winnercompetitorprintf“ Player d Win the Game.n“,competitor;else ifchk_fullprintf“ No One Win the Game.n“;elsebENDFALSE;/*change the turn of the players*/competitorplayer;ifplayerPLAYER_AplayerPLAYER_B;elseplayerPLAYER_Aprintf“nnthe command completed successfully.nn“;return 0;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值