三子棋C語言實現

2021-08-09 22:58:19 字數 2022 閱讀 8788

要寫這個三子棋的程式我們分為三個部分首先是宣告函式的標頭檔案,我們分別宣告了五個函式,初始化棋盤,列印棋盤,玩家走,電腦走,檢查是否贏了。之後我們寫測試**然後分別來實現這五個函式

#define _crt_secure_no_warnings 1

#ifndef __game_h__

#define __game_h__

#include

#define row 3

#define col 3

void initboard(char arr[row][col], int row, int col);

void disaplyboard(char arr[row][col], int row, int col);

void playmove(char arr[row][col],int row,int col);

void computermove(char arr[row][col], int row, int col);

char checkwin(char arr[row][col], int row, int col);

#endif

測試**

#define _crt_secure_no_warnings 1

#include

#include

#include"game.h"

void print()

void game()

; initboard(arr,row,col);

disaplyboard(arr, row, col);

while (1)

computermove(arr, row, col);

disaplyboard(arr, row, col);

if (checkwin(arr, row, col) != ' ')

}if (checkwin(arr, row, col) == 'x')

else

if (checkwin(arr, row, col) == '$')

else

if (checkwin(arr, row, col) == 'q')

}int main()

if (input == 1)

} while (input);

system("pause");

return

0;}

總的來說這段**就是呼叫幾個主要的函式接下來我們來實現這幾個主要的函式

#define _crt_secure_no_warnings 1

#include"game.h"

void disaplyboard(char arr[row][col], int row, int col)

}}void initboard(char arr[row][col], int row, int col)

}void playmove(char arr[row][col], int row, int col)

else

}}void computermove(char arr[row][col], int row, int col)

}}int checknull(char arr[row][col], int row, int col)

}return1;}

char checkwin(char arr[row][col], int row, int col)

}for (i = 0; i < col; i++)

}if (arr[0][0] == arr[1][1] && arr[1][1] == arr[2][2] && arr[0][0] != ' ')

if (arr[0][2] == arr[1][1] && arr[1][1] == arr[2][0] && arr[0][2] != ' ')

if (checknull(arr, row, col))

return

' ';

}

C語言實現三子棋

game.h define crt secure no warnings 1 ifndef game h define game h include include include include define rows 3 define cols 3 void init board char bo...

C語言實現三子棋

實現三子棋程式,只要我們能夠理清楚思路,就可以知道其實它的做法並不難,重點在於實際寫 時需要多關注細節。這裡我們可以寫完一塊就可以立馬執行程式檢查是否如我們所想的效果出現,如若不是便可立即查錯糾錯。如下。test.c include include include include game.h vo...

C語言實現三子棋

本文是編寫乙個小專案 三子棋 有單人模式 人機 和雙人模式 人人 兩種 主要步驟 1 首先建立三個檔案 這是我建立的,當熱名字可以隨個人愛好起,main.c中主要實現的時總選單,只需呼叫函式即可 sanziqi.h中實現的 是函式的宣告,當然在該專案中我並沒有分太多的函式 sanziqi.c中實現的...