Go to file
Falko Victor Habel e7e9463789 added the URL 2024-05-19 17:38:31 +02:00
game Fixed bug, where the popup window opened twice. 2024-04-29 15:32:13 +02:00
gameControl changed Camelcase error in Code 2024-04-24 21:28:48 +02:00
opponent fixed Bug related to Minimax 2024-05-18 23:50:42 +02:00
resources added Icon for the programm. 2024-04-29 11:09:04 +02:00
theme added a custom Theme using the fyne-theme-generator 2024-04-25 08:34:25 +02:00
.gitignore Initial commit 2024-04-23 08:17:15 +00:00
LICENSE Added a folder structure. 2024-04-23 10:25:40 +02:00
README.md added the URL 2024-05-19 17:38:31 +02:00
go.mod added go.mod and go.sum file containing dependences 2024-04-23 13:56:49 +02:00
go.sum added go.mod and go.sum file containing dependences 2024-04-23 13:56:49 +02:00
main.go First runnable version: Implemented main.go and created basic game window 2024-04-23 13:56:27 +02:00

README.md

Tic-Tac-Toe in Go

Video Demo: https://youtu.be/-IJmxy8wxKw

Description:

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.

  • To install the Fyne framework and ensure the game's smooth operation, two essential components are required: C compiler (for interfacing with system graphics drivers), and a system graphics driver.

You can install the Fyne framework using the following commands in your terminal:

go get fyne.io/fyne/v2@latest
go install fyne.io/fyne/v2/cmd/fyne@latest

How to run the application

Please be aware that for some platforms, you may need to install external dependencies to ensure proper functionality.

You can find more detailed information about these dependencies and how to install here: dependencies.

  1. 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`
cd tictactoe
  1. 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:s
# Windows:
fyne package -os windows -icon ./resources/icon.png
# Linux:
fyne package -os linux -icon ./resources/icon.png # gives you a .tar.xz file
# Android
fyne package -os android -appID com.example.myapp -icon ./resources/icon.png
# MacOS:
fyne package -os macos -icon ./resources/icon.png # not tested
# IOS
fyne package -os ios -appID com.example.myapp -icon ./resources/icon.png # not tested

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 simple AI 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: A Restart 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.