diff --git a/三子棋/Makefile.win b/三子棋/Makefile.win new file mode 100644 index 0000000..cf4f923 --- /dev/null +++ b/三子棋/Makefile.win @@ -0,0 +1,32 @@ +# Project: +# Makefile created by Dev-C++ 6.7.5 + +CPP = g++.exe -D__DEBUG__ +CC = gcc.exe -D__DEBUG__ +WINDRES = windres.exe +OBJ = test.o game.o +LINKOBJ = test.o game.o +LIBS = -L"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/" -L"d:/files/software/dev-cpp/mingw32/lib/gcc/" -L"d:/files/software/dev-cpp/mingw32/mingw32/lib/" -L"d:/files/software/dev-cpp/mingw32/lib/" -L"D:/files/software/Dev-Cpp/MinGW32/lib" -L"D:/files/software/Dev-Cpp/MinGW32/mingw32/lib" -g3 -static +INCS = -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include" -I"d:/files/software/dev-cpp/mingw32/include" -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include-fixed" +CXXINCS = -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include/c++" -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include/c++/mingw32" -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include/c++/backward" -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include" -I"d:/files/software/dev-cpp/mingw32/include" -I"d:/files/software/dev-cpp/mingw32/lib/gcc/mingw32/9.2.0/include-fixed" +BIN = .exe +CXXFLAGS = $(CXXINCS) -Wall -Wextra -g3 +ENCODINGS = -finput-charset=utf-8 -fexec-charset=gbk +CFLAGS = $(INCS) -Wall -Wextra -g3 +RM = del /q /f + +.PHONY: all all-before all-after clean clean-custom + +all: all-before $(BIN) all-after + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CC) $(LINKOBJ) -o "$(BIN)" $(LIBS) + +test.o: test.c game.h + $(CC) -c test.c -o test.o $(CFLAGS) + +game.o: game.c game.h + $(CC) -c game.c -o game.o $(CFLAGS) diff --git a/三子棋/game.c b/三子棋/game.c new file mode 100644 index 0000000..06d2f64 --- /dev/null +++ b/三子棋/game.c @@ -0,0 +1,116 @@ +#include "game.h" +//ʼ +void initBoard(char board[ROW][COL],int row,int col){ + int i = 0; + int j = 0; + for(i = 0;i < row;i++){ + for(j = 0;j < col;j++){ + board[i][j] = ' '; + } + } +} +//չʾ +void displayBoard(char board[ROW][COL],int row,int col){ + int i = 0; + for(i = 0;i < row;i++){ + int j = 0; + for(j = 0;j < col;j++){ + printf(" %c ",board[i][j]); + if(j < col -1) + printf("|"); + } + printf("\n"); + if(i < row -1){ + int j = 0; + for(j = 0;j< col;j++){ + printf("---"); + if(j < col -1) + printf("|"); + } + printf("\n"); + } + } +} +// +void playMove(char board[][COL],int row,int col){ + int x = 0; + int y = 0; + printf(">\n"); + while(1){ + printf(":>\n"); + scanf("%d %d",&x,&y); + //жϷ + if(x >= 1 && x <= row && y>= 1 && y<= col){ + // + //жǷռ + if(board[x-1][y-1] == ' '){ + board[x-1][y-1] = '*'; + break; + }else{ + printf("걻ռã\n"); + } + }else{ + printf("Ƿ\n"); + } + } + +} +// +void computerMove(char board[][COL],int row,int col){ + printf("\n"); + while(1){ + int x = rand() % ROW; + int y = rand() % COL; + //жλǷռ + if(board[x][y] == ' '){ + board[x][y] = '#'; + break; + } + } +} +//жǷ +int isFull(char board[ROW][COL],int row,int col){ + int i = 0 ; + int j = 0; + for(i = 0;i < row;i++){ + for(j = 0;j< col;j++){ + if(board[i][j] == ' '){ + //û + return 0; + } + } + } + return 1;// +} +//жϷ +char isWin(char board[ROW][COL],int row,int col){ + int i = 0; + //ж + for(i = 0;i < row;i++){ + if(board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][1] != ' '){ + return board[i][1]; + } + } + //ж + for(i = 0;i< col;i++){ + if(board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[1][i] != ' '){ + return board[1][i]; + } + } + //ж϶Խ + if(board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[1][1] != ' '){ + return board[1][1]; + } + if(board[0][2] == board[1][1] && board[1][1] == board[2][0] && board[1][1] != ' '){ + return board[1][1]; + } + //жƽ + //10 + int ret = isFull(board,row,col); + if(ret == 1){ + return 'Q'; + } + // + return 'C'; + +} diff --git a/三子棋/game.h b/三子棋/game.h new file mode 100644 index 0000000..c42d60a --- /dev/null +++ b/三子棋/game.h @@ -0,0 +1,29 @@ +//ͷļ +#include +#include +#include + +//ŵĶ +#define ROW 3 +#define COL 3 + +// + +//ʼ +void initBiard(char board[ROW][COL],int row,int col); + +//ӡ̵ĺ +void displayBoard(char board[ROW][COL],int row,int col); + +// +void playMove(char board[ROW][COL],int row,int col); + +// +void computerMove(char board[][COL],int row,int col); + +//жϷ +//1. Ӯ -- * +//2. Ӯ -- # +//3. ƽ -- Q +//4. Ϸ -- C +char isWin(char board[ROW][COL],int row,int col); diff --git a/三子棋/game.o b/三子棋/game.o new file mode 100644 index 0000000..3559593 Binary files /dev/null and b/三子棋/game.o differ diff --git a/三子棋/test.c b/三子棋/test.c new file mode 100644 index 0000000..9805774 --- /dev/null +++ b/三子棋/test.c @@ -0,0 +1,74 @@ +//test.c Ϸ߼ +//game.hϷصĺͷļİ +//game.c Ϸغʵ +#include "game.h" +void menu(){ + printf("*************************\n"); + printf("**** 1.play **********\n"); + printf("**** 0.exit **********\n"); + printf("*************************\n"); + +} +void game(){ + + //洢---ά + char board[ROW][COL]; + + //ʼ -- ʼո + initBoard(board,ROW,COL); + + //ӡ Ǵӡ + displayBoard(board,ROW,COL); + + char ret = 0;//Ϸ״̬ + while(1){ + + // + playMove(board,ROW,COL); + displayBoard(board,ROW,COL); + + //жǷӮϷ + ret = isWin(board,ROW,COL); + if(ret != 'C'){ + break; + } + // + computerMove(board,ROW,COL); + displayBoard(board,ROW,COL); + + //жϵǷӮϷ + ret = isWin(board,ROW,COL); + if(ret != 'C'){ + break; + } + } + if(ret == '*'){ + printf("Ӯ\n"); + }else if(ret == '#'){ + printf("Ӯ\n"); + }else{ + printf("ƽ\n"); + } + displayBoard(board,ROW,COL); +} +int main(){ + int input = 0; + srand((unsigned int)time(NULL)); + do{ + menu(); + printf("ѡ>"); + scanf("%d",&input); + switch(input){ + case 1: + game(); + break; + case 0: + printf("˳Ϸ\n"); + break; + default: + printf("ѡѡ\n"); + break; + } + }while(input); + return 0; +} diff --git a/三子棋/test.o b/三子棋/test.o new file mode 100644 index 0000000..8ca26fa Binary files /dev/null and b/三子棋/test.o differ diff --git a/三子棋/三子棋.dev b/三子棋/三子棋.dev new file mode 100644 index 0000000..a78c9d3 --- /dev/null +++ b/三子棋/三子棋.dev @@ -0,0 +1,93 @@ +[Project] +FileName=.dev +Name= +UnitCount=3 +Type=1 +Ver=2 +ObjFiles= +Includes= +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker= +IsCpp=0 +Icon= +ExeOutput= +ObjectOutput= +LogOutput= +LogOutputEnabled=0 +OverrideOutput=0 +OverrideOutputName= +HostApplication= +UseCustomMakefile=0 +CustomMakefile= +UsePrecompiledHeader=0 +PrecompiledHeader= +CommandLine= +Folders=ͷļ,Դļ +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=1 +CompilerSettings=0000000000110000000001000 +StaticLink=1 +AddCharset=1 +UseUTF8=0 + +[Unit1] +FileName=test.c +Folder=Դļ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +DetectEncoding=0 +Encoding=0 +CompileCpp=0 + +[VersionInfo] +Major=1 +Minor=0 +Release=0 +Build=0 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 +SyncProduct=1 + +[Unit2] +FileName=game.c +CompileCpp=0 +Folder=Դļ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +DetectEncoding=0 +Encoding=0 + +[Unit3] +FileName=game.h +CompileCpp=0 +Folder=ͷļ +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= +DetectEncoding=0 +Encoding=0 + diff --git a/三子棋/三子棋.exe b/三子棋/三子棋.exe new file mode 100644 index 0000000..0af864e Binary files /dev/null and b/三子棋/三子棋.exe differ diff --git a/三子棋/三子棋.layout b/三子棋/三子棋.layout new file mode 100644 index 0000000..279f096 --- /dev/null +++ b/三子棋/三子棋.layout @@ -0,0 +1,18 @@ +[Editors] +Order=0,2,1 +Focused=0 +[Editor_0] +CursorCol=2 +CursorRow=44 +TopLine=1 +LeftChar=1 +[Editor_1] +CursorCol=15 +CursorRow=110 +TopLine=62 +LeftChar=1 +[Editor_2] +CursorCol=14 +CursorRow=7 +TopLine=2 +LeftChar=1 diff --git a/三子棋/未命名2 b/三子棋/未命名2 new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/三子棋/未命名2 differ diff --git a/三子棋/未命名3.o b/三子棋/未命名3.o new file mode 100644 index 0000000..68e42c3 Binary files /dev/null and b/三子棋/未命名3.o differ