commit 7a0e16f742e484ba5dabd6f5da8150bfef20c2b0 Author: louiscklaw Date: Sat Feb 1 01:58:29 2025 +0800 update, diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d54c38a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,31 @@ +*.mp4 filter=lfs diff=lfs merge=lfs +*.zip filter=lfs diff=lfs merge=lfs +*.7z filter=lfs diff=lfs merge=lfs +*.tar.gz filter=lfs diff=lfs merge=lfs +*.jpg filter=lfs diff=lfs merge=lfs +*.png filter=lfs diff=lfs merge=lfs +*.avif filter=lfs diff=lfs merge=lfs +*.webm filter=lfs diff=lfs merge=lfs +*.mkv filter=lfs diff=lfs merge=lfs + +# Documents +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain + +*.gif filter=lfs diff=lfs merge=lfs +*.GIF filter=lfs diff=lfs merge=lfs +*.bmp filter=lfs diff=lfs merge=lfs +*.BMP filter=lfs diff=lfs merge=lfs +*.tiff filter=lfs diff=lfs merge=lfs +*.TIFF filter=lfs diff=lfs merge=lfs +*.wav filter=lfs diff=lfs merge=lfs +*.WAV filter=lfs diff=lfs merge=lfs +*.log filter=lfs diff=lfs merge=lfs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67a5a14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/~*.* \ No newline at end of file diff --git a/ENGG1110Project.pdf b/ENGG1110Project.pdf new file mode 100644 index 0000000..f8ee862 Binary files /dev/null and b/ENGG1110Project.pdf differ diff --git a/SampleRun1.txt b/SampleRun1.txt new file mode 100644 index 0000000..fdf68ab --- /dev/null +++ b/SampleRun1.txt @@ -0,0 +1,138 @@ +Enter the number of human players [1-2]: +2 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|3| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +5 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|3| +# Game Board 2 # +|7|8|9| +|4|X|6| +|1|2|3| +# Player 2's turn # +Choose the game board: +2 +Choose the cell: +7 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +5 + +# Game Board 1 # +|7|8|9| +|4|X|6| +|1|2|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|3| +# Player 2's turn # +Choose the game board: +2 +Choose the cell: +3 + +# Game Board 1 # +|7|8|9| +|4|X|6| +|1|2|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +7 + +# Game Board 1 # +|X|8|9| +|4|X|6| +|1|2|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +# Player 2's turn # +Choose the game board: +1 +Choose the cell: +1 + +# Game Board 1 # +|X|8|9| +|4|X|6| +|X|2|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +2 + +# Game Board 1 # +|X|8|9| +|4|X|6| +|X|X|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +# Player 2's turn # +Choose the game board: +1 +Choose the cell: +6 + +# Game Board 1 # +|X|8|9| +|4|X|X| +|X|X|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +4 + +# Game Board 1 # +|X|8|9| +|X|X|X| +|X|X|3| +# Game Board 2 # +|X|8|9| +|4|X|6| +|1|2|X| +Congratulations! Player 2 wins! \ No newline at end of file diff --git a/SampleRun2.txt b/SampleRun2.txt new file mode 100644 index 0000000..5840376 --- /dev/null +++ b/SampleRun2.txt @@ -0,0 +1,136 @@ +Enter the number of human players [1-2]: +2 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|3| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +0 +Input out of range. Please input again: +3 +Input out of range. Please input again: +1 +Choose the cell: +0 +Input out of range. Please input again: +10 +Input out of range. Please input again: +3 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|X| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Player 2's turn # +Choose the game board: +1 +Choose the cell: +3 +The chosen cell is occupied. Please input again: +4 + +# Game Board 1 # +|7|8|9| +|X|5|6| +|1|2|X| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +3 + +# Game Board 1 # +|7|8|9| +|X|5|6| +|1|2|X| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|X| +# Player 2's turn # +Choose the game board: +2 +Choose the cell: +4 + +# Game Board 1 # +|7|8|9| +|X|5|6| +|1|2|X| +# Game Board 2 # +|7|8|9| +|X|5|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +5 + +# Game Board 1 # +|7|8|9| +|X|X|6| +|1|2|X| +# Game Board 2 # +|7|8|9| +|X|5|6| +|1|2|X| +# Player 2's turn # +Choose the game board: +1 +Choose the cell: +6 + +# Game Board 1 # +|7|8|9| +|X|X|X| +|1|2|X| +# Game Board 2 # +|7|8|9| +|X|5|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +1 +The chosen game board is dead. Please input again: +2 +Choose the cell: +5 + +# Game Board 1 # +|7|8|9| +|X|X|X| +|1|2|X| +# Game Board 2 # +|7|8|9| +|X|X|6| +|1|2|X| +# Player 2's turn # +Choose the game board: +2 +Choose the cell: +6 + +# Game Board 1 # +|7|8|9| +|X|X|X| +|1|2|X| +# Game Board 2 # +|7|8|9| +|X|X|X| +|1|2|X| +Congratulations! Player 1 wins! \ No newline at end of file diff --git a/SampleRun3.txt b/SampleRun3.txt new file mode 100644 index 0000000..836228c --- /dev/null +++ b/SampleRun3.txt @@ -0,0 +1,138 @@ +Enter the number of human players [1-2]: +1 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|1|2|3| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +1 +Choose the cell: +1 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|2|3| +# Game Board 2 # +|7|8|9| +|4|5|6| +|1|2|3| +# Computer's turn # +Choose the game board: +2 +Choose the cell: +9 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|2|3| +# Game Board 2 # +|7|8|X| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +8 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|2|3| +# Game Board 2 # +|7|X|X| +|4|5|6| +|1|2|3| +# Computer's turn # +Choose the game board: +1 +Choose the cell: +2 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|3| +# Game Board 2 # +|7|X|X| +|4|5|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +5 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|3| +# Game Board 2 # +|7|X|X| +|4|X|6| +|1|2|3| +# Computer's turn # +Choose the game board: +1 +Choose the cell: +3 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|X| +# Game Board 2 # +|7|X|X| +|4|X|6| +|1|2|3| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +4 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|X| +# Game Board 2 # +|7|X|X| +|X|X|6| +|1|2|3| +# Computer's turn # +Choose the game board: +2 +Choose the cell: +3 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|X| +# Game Board 2 # +|7|X|X| +|X|X|6| +|1|2|X| +# Player 1's turn # +Choose the game board: +2 +Choose the cell: +6 + +# Game Board 1 # +|7|8|9| +|4|5|6| +|X|X|X| +# Game Board 2 # +|7|X|X| +|X|X|X| +|1|2|X| +Computer wins! \ No newline at end of file diff --git a/gitUpdate.bat b/gitUpdate.bat new file mode 100644 index 0000000..37e4070 --- /dev/null +++ b/gitUpdate.bat @@ -0,0 +1,7 @@ +git status . + +@pause + +git add . +git commit -m"update ProGamerPC," +start git push \ No newline at end of file diff --git a/gitUpdate.sh b/gitUpdate.sh new file mode 100755 index 0000000..c96734f --- /dev/null +++ b/gitUpdate.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -ex + +git config --global http.version HTTP/1.1 +git config --global lfs.allowincompletepush true +git config --global lfs.locksverify true +git config --global http.postBuffer 5368709120 + +git add . + +git commit -m 'update,' + +git push + +echo "done" diff --git a/main.c b/main.c new file mode 100644 index 0000000..236d596 --- /dev/null +++ b/main.c @@ -0,0 +1,153 @@ +/** + * ENGG1110 Problem Solving by Programming + * + * Course Project + * + * I declare that the project here submitted is original + * except for source material explicitly acknowledged, + * and that the same or closely related material has not been + * previously submitted for another course. + * I also acknowledge that I am aware of University policy and + * regulations on honesty in academic work, and of the disciplinary + * guidelines and procedures applicable to breaches of such + * policy and regulations, as contained in the website. + * + * University Guideline on Academic Honesty: + * https://www.cuhk.edu.hk/policy/academichonesty/ + * + * Student Name : + * Student ID : + * Class/Section : + * Date : + */ + +#include +/* NO other header files are allowed */ + +/* NO global variables are allowed */ + + + +/* Initialize the specified game board. + Please design your own representation for the game board. For example: + - Does gameBoard[0][0] represent the top left corner or the bottom left corner of the game board? + - Which numbers represent empty cells and crosses? */ +void initGameBoard(int gameBoard[3][3]) { + + // TODO: Complete this part + +} + + + +/* Display the specified game board on the screen. + You are required to exactly follow the output format stated in the project specification. + IMPORTANT: Using other output format will result in mark deduction. */ +void printGameBoard(int gameBoard[3][3]) { + + // TODO: Complete this part + +} + + + +/* Display the two game boards on the screen. + Implemented for you already and no change is needed */ +void printTwoGameBoards(int gameBoard1[3][3], int gameBoard2[3][3]) { + printf("\n"); + printf("# Game Board 1 #\n"); + printGameBoard(gameBoard1); + printf("# Game Board 2 #\n"); + printGameBoard(gameBoard2); +} + + + +/* Return 1 if the specified game board is dead (i.e., having three-in-a-row of crosses), otherwise return 0. */ +int isGameBoardDead(int gameBoard[3][3]){ + + // TODO: Complete this part + +} + + + +/* Update the specific game board according to the user input. + The user input may not be valid, but you can assume that it must be an integer. */ +void updateGameBoard(int gameBoard[3][3]) { + + // TODO: Complete this part + +} + + + +/* Choose a game board and place a cross according to the user inputs. + The user input may not be valid, but you can assume that it must be an integer. */ +void placeCrossByHumanPlayer(int gameBoard1[3][3], int gameBoard2[3][3]) { + + // TODO: Complete this part + +} + + + +/* Return the number of crosses on the specified game board. */ +int countNumOfCrosses(int gameBoard[3][3]) { + + // TODO: Complete this part + +} + + + +/* Determine the next move of the computer player and update the corresponding game board accordingly. + You are required to exactly follow the strategy mentioned in the project specification. + IMPORTANT: Using other strategies will result in mark deduction. */ +void placeCrossByComputerPlayer(int gameBoard1[3][3], int gameBoard2[3][3]) { + + // TODO: Complete this part + +} + + + +/* The main function */ +int main() +{ + /* Local variables */ + int gameBoard1[3][3]; // Represent Game Board 1 + int gameBoard2[3][3]; // Represent Game Board 2 + int currentPlayer; // 1: Player 1 2: Player 2 + int gameEnd; // 0: The game continues 1: The game ends + int numOfHumanPlayers; // 1 or 2 + + /* Initialize the local variables */ + initGameBoard(gameBoard1); + initGameBoard(gameBoard2); + currentPlayer = 1; + gameEnd = 0; + printf("Enter the number of human players [1-2]:\n"); + scanf("%d", &numOfHumanPlayers); // You can assume that the user input must be valid here + + /* Uncomment the following statements to test whether the printTwoGameBoards() and the placeCrossByHumanPlayer() functions are implemented correctly. + You can add more if you wish. + After testing, you can delete them or move them elsewhere. */ + //printTwoGameBoards(gameBoard1, gameBoard2); + //printf("# Player 1's turn #\n"); + //placeCrossByHumanPlayer(gameBoard1, gameBoard2); + //printTwoGameBoards(gameBoard1, gameBoard2); + //printf("# Player 2's turn #\n"); + //placeCrossByHumanPlayer(gameBoard1, gameBoard2); + //printTwoGameBoards(gameBoard1, gameBoard2); + + /* Game start + If there are two human players, they are Player 1 and Player 2 + If there is only one human player, he/she is Player 1 and another player is the computer + For both cases, Player 1 moves first + Hint: use a while loop */ + + // TODO: Complete this part + + return 0; +} \ No newline at end of file