Kỹ thuật lập trình UTE: (Buổi 06_2) Trò chơi caro
Introduction to Caro Game Data Handling
Overview of the Caro Game File Structure
- The session begins with an introduction to handling a data file that stores the current state of a Caro game, including whether it has ended or if there is a winner.
- The game board is represented as a two-dimensional array, where empty cells are indicated by specific values for processing.
Value Assignments in the Game Matrix
- Specific values are assigned to represent different states:
0indicates that player O has made a move,
1indicates player X's move,
-1signifies an empty cell where no moves have been made yet.
Creating and Formatting the Data File
- Instructions are provided on how to create the data file using Excel, emphasizing the need for proper formatting and value assignments.
- The initial setup involves creating a blank file and filling it with
-1for all empty cells, ensuring that the matrix size is set at 10x10.
Inputting Values into the Matrix
- Users are guided on entering values into their matrix, stressing accuracy in maintaining ten entries per row and column.
- It’s suggested to use arrow keys for navigation while inputting values instead of tabs, which helps maintain structure from copied data.
Developing Functions in Microsoft Visual Studio
Setting Up Program Functions
- Transitioning to programming in Microsoft Visual Studio, several functions need to be declared for processing game data effectively.
Key Functions Required:
- File Reading Function:
- This function reads data from a specified filename into a square matrix (A), defined by its size (n).
- Matrix Printing Function:
- A function designed to print out the contents of the matrix based on given dimensions (D x C).
- Game State Validation Function:
- This function checks if the game's state is valid by comparing moves made by both players O and X.
Validating Game Moves
- The validation function ensures that turns alternate correctly between players; discrepancies indicate potential cheating or errors in gameplay.
- It checks if either player's number of moves exceeds one more than their opponent's, which would suggest invalid play.
Conclusion on Writing Essential Functions
Final Steps in Programming Logic
- Participants are encouraged to write these three essential functions sequentially as part of their main program logic.
Implementing a Validity Check in Programming
Overview of Function Implementation
- The speaker discusses the process of creating a validity check function, emphasizing that it can be either copied and pasted or rewritten as needed.
- A temporary return statement (
return true) is introduced to ensure the function compiles correctly, even though it currently lacks specific functionality.
Function Return Type Considerations
- The function is designed to return a boolean value (
bool), which necessitates the inclusion of a placeholder return statement for initial testing purposes.
- The speaker notes that this placeholder will be replaced with actual logic later when the body of the function is developed.