900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > c语言井字棋程序设计报告 C语言编写的井字棋.doc

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

时间:2019-02-11 16:29:26

相关推荐

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;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。