Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Othello Game

A JavaFX implementation of the classic board game Othello (also known as Reversi) with AI opponents of varying difficulty levels.

Description

This is a desktop application that allows players to enjoy the strategic board game Othello. The game features a graphical user interface built with JavaFX and includes three different AI opponents with distinct playing strategies, as well as a two-player mode for local multiplayer.

Game Rules

Othello is played on an 8x8 board with black and white pieces. The objective is to have the majority of your colored pieces on the board at the end of the game.

  • Players take turns placing pieces on the board
  • A valid move must flank one or more opponent pieces between the newly placed piece and another piece of the player's color
  • All flanked opponent pieces are flipped to the current player's color
  • If a player has no valid moves, their turn is skipped
  • The game ends when neither player can make a valid move
  • The player with the most pieces wins

Features

  • Two-Player Mode: Play against a friend on the same computer
  • Single-Player Mode: Challenge one of three AI opponents:
    • GARZA (Easy): Makes random moves from all available options
    • DODO (Medium): Strategically chooses moves that capture the least material (defensive strategy)
    • LORO (Hard): Plays aggressively by selecting moves that capture the most material
  • Game History: Ability to save and review game moves
  • Visual Interface: Clean and intuitive JavaFX-based GUI
  • Move Validation: Automatic validation of legal moves

Project Structure

src/
├── controladores/          # Controllers for JavaFX views
│   ├── Main.java          # Application entry point
│   ├── MenuPrincipalController.java
│   ├── Pantalla1JugadorController.java
│   ├── Pantalla2JugadoresController.java
│   ├── PantallaJuegoController.java
│   └── AcercaDeController.java
├── estructuras/           # Data structures
│   ├── Nodo.java         # Node class for board representation
│   └── Tablero.java      # Board class with game logic
├── modelo/               # Game models
│   ├── Jugador.java      # Player base class
│   ├── Bot.java          # AI base class
│   ├── Garza.java        # Easy AI
│   ├── Dodo.java         # Medium AI
│   ├── Loro.java         # Hard AI
│   └── Partida.java      # Game match class
├── utilidades/           # Utilities
│   └── Archivo.java      # File handling for game history
└── vista/                # FXML view files
    ├── MenuPrincipal.fxml
    ├── Pantalla1Jugador.fxml
    ├── Pantalla2Jugadores.fxml
    ├── PantallaJuego.fxml
    └── AcercaDe.fxml

How It Works

Board Representation

The game board is implemented using a custom linked node structure (Nodo.java) where each square on the 8x8 board is represented by a node. Each node maintains references to its eight neighbors (up, down, left, right, and four diagonals), creating an efficient graph structure for move validation and piece flipping.

Move Validation and Execution

The Tablero.java class contains the core game logic:

  1. Move Validation (evaluarJugada): Checks if a move is legal by verifying that it flanks opponent pieces in at least one direction
  2. Move Execution (realizarJugada): Places the piece and flips all flanked opponent pieces in all eight directions
  3. Possible Moves (jugadasPosibles): Calculates all valid moves for the current player and handles turn skipping when no moves are available

AI Strategies

Each AI bot extends the Bot class and implements its own realizarJugada method:

  • GARZA: Purely random selection from all legal moves
  • DODO: Evaluates all moves and randomly selects from those that capture the fewest pieces (anti-greedy strategy)
  • LORO: Evaluates all moves and randomly selects from those that capture the most pieces (greedy strategy)

Game Flow

  1. Application starts with the main menu (MenuPrincipal.fxml)
  2. Player selects game mode (1 Player or 2 Players)
  3. In single-player mode, player selects AI difficulty
  4. Game board is displayed (PantallaJuego.fxml)
  5. Players alternate turns until no valid moves remain
  6. Game concludes and shows the winner
  7. Option to save game history to file

Requirements

  • Java Development Kit (JDK) 8 or higher
  • JavaFX SDK (included in JDK 8, separate download for JDK 11+)
  • NetBeans IDE (recommended) or any Java IDE with JavaFX support

Building and Running

Using NetBeans:

  1. Open the project in NetBeans
  2. Right-click on the project and select "Clean and Build"
  3. Run the project (F6 or right-click and select "Run")

Using Command Line:

# Compile
ant compile

# Run
ant run

Game History

Games can be saved to partidas.txt, recording:

  • Player names
  • Sequence of moves in algebraic notation (e.g., e5, d6)
  • Game outcome

Technical Highlights

  • Model-View-Controller (MVC) architecture
  • Custom graph-based data structure for efficient board operations
  • Algebraic notation for move representation (columns a-h, rows 1-8)
  • Object-oriented design with inheritance (Bot hierarchy)
  • JavaFX for modern GUI with FXML layouts

Author

Luis Fernando - May 2022

License

This project is an educational implementation of Othello/Reversi.

About

Proyecto académico de un othello funcional en java utilizando una estructura de datos basada en nodos multidireccionales e interfaz con javafx

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages