Falko Victor Habel 5d553ca386 | ||
---|---|---|
game | ||
gameControl | ||
opponent | ||
resources | ||
theme | ||
.gitignore | ||
LICENSE | ||
README.md | ||
go.mod | ||
go.sum | ||
main.go |
README.md
TicTacToe Game
Overview
This Tic-Tac-Toe game is a simple single-player experience where the player takes on a computer-controlled opponent. The goal of the game is to make a horizontal, vertical, or diagonal line of their chosen symbol (X or O) on a 3x3 grid. The game ends when one player successfully achieves three marks in a row or when all spaces are filled, resulting in a draw if neither player has achieved this condition.
Prerequisites
Go
programming language installed on your machine: To run the TicTacToe application, you need to have the Go programming language installed on your computer. You can download and install Go from the official website (https://golang.org/dl/). Follow the instructions for your specific operating system to set up the Go environment.
Fyne
framework for building cross-platform GUI applications: The application uses the Fyne framework to create the graphical user interface (GUI) for the TicTacToe game. You can install the Fyne framework using the following command:
go get fyne.io/fyne/v2@latest
How to run the application
- Clone the repository: Open your terminal and run the following command to clone the TicTacToe repository to your local machine:
git clone https://gitea.fabelous.app/Fabel/TicTacToe.git` #This is my private gitea server, which is currently not always available
cd tictactoe
- Install dependencies:
- To ensure that all the required packages are installed, run the following command in your terminal within the project directory:
go mod tidy
- This will download and install any missing dependencies specified in the go.mod file. 2. Run the application: Execute the main Go file to start the TicTacToe game application:
go run main.go
- Build the executable: After installing the dependencies, you can build an executable file for your operating system using the go build command:
# Windows:
fyne package -os windows -icon ./resources/icon.png
# Linux:
fyne package -os linux -icon ./resources/icon.png #Could not test
# MacOS:
fyne package -os macos -icon ./resources/icon.png #Could not Test
This will create an executable file named "tictactoe" in your project's directory that you can run to start the TicTacToe game application.
Game Functionality
The TicTacToe game application offers a range of features to create an enjoyable gaming experience for players:
-
A graphical user interface (GUI) built using the Fyne framework, which allows for a visually appealing and responsive gameplay experience.
-
3x3 grid board: The game features a traditional TicTacToe grid consisting of nine spaces, where players take turns marking an empty space with their chosen symbol.
-
Real-time gameplay: Players can interact with the game in real-time by clicking on the buttons representing the empty spaces on the grid.
-
AI opponent
: The application includes a simpleAI opponent
that plays the game using the minimax algorithm, providing a challenge for human players. -
Game over detection: The game detects when a player has won by making three marks in a row or if all spaces are filled without a winner, and updates the game status accordingly.
Restart
button: ARestart
button is available to start a new game after the previous game ends, allowing for continuous play without needing to restart the application.
Code Structure
The TicTacToe application's code is organized into several Go files, each responsible for specific aspects of the application:
main.go
:
This file serves as the main entry point for the application. It initializes the Fyne app and creates the game window.
window.go
:
The window.go
file is responsible for creating the main window of the Tic-Tac-Toe game using the Fyne library. This file defines a single function, CreateWindow
, which sets up the application, creates a new window, and organizes the user interface elements. The result is returned as an instance of fyne.Window.
minimax.go
:
This file contains the implementation of the minimax algorithm. The function minimax takes the current state of the game board, the depth of the algorithm, whether it is the maximizing player's turn or not, and alpha and beta values for alpha-beta pruning. It returns the bestNext Move for the AI Player.
check.go
:
This file contains utility functions to check if a game state meets certain conditions. The function PlayerHasWon checks whether a player has won the game by having all their symbols in a row, column, or diagonal. The function BoardisFull checks if the game board is full and there are no more moves left.
gameloop.go
:
gameloop.go
contains the game loop and GUI logic for the Tic-Tac-Toe application. It uses the Fyne library to create a user interface with a grid of buttons representing the Tic-Tac-Toe board. The file includes functions to create the button grid, manage button interactions, update the game board, and handle player and computer moves. The main game loop function Gameloop handles these actions and ensures that the game progresses smoothly, alternating between the human player's move and the computer's move.