michalskibinski109 / 2048

Implementation of 2048 game. This is web application with python backend and (js)jquery and bootstrap frontend.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

2048 Game

This project implements the popular game 2048. The game is built using a combination of Python for the backend and HTML, CSS, and JavaScript for the frontend.

Contributors

I am absolutelly open to contributions:

potentaial tasks:

  • refactor frontend so it will be scallable to portable devices
  • Add new engine to game. It could be DQNagent, or some classic engine.

Features

  • The game is played on a grid with dimensions defined by the shape argument.
  • The game starts with two tiles, each with a value of either 2 or 4.
  • The player can move the tiles in four directions: up, down, left, and right.
  • When two tiles with the same value collide while moving, they merge into a new tile with the sum of their values.
  • After each move, a new tile with a value of either 2 or 4 appears on the board.
  • The goal of the game is to reach a tile with a value of 2048.

Installation

  1. Clone the repository:
git clone https://github.com/michalskibinski109/2048.git
  1. Install the required dependencies:
pip install -r requirements.txt
  1. Run the application:
python main.py

The application will be accessible at http://localhost:8000.

Files

  • board.py: Contains the implementation of the game board and its operations.
  • game.py: Implements the game logic and provides methods to play the game.
  • engine.py: Implements the engine to find the best move using the minimax algorithm.
  • main.py: Sets up the API endpoints and runs the FastAPI server.
  • templates/index.html: HTML template for the frontend of the game.
  • static/main.js: JavaScript code for handling user interactions and making API requests.
  • static/style.css: CSS styling for the frontend.

API Endpoints

  • GET /: Renders the game interface.
  • GET /board: Returns the current state of the game board and score as JSON.
  • GET /ai_move: Performs an AI move and returns the updated game board and score as JSON.
  • POST /move/{direction}: Moves the tiles in the specified direction and returns the updated game board and score as JSON.
  • POST /reset: Resets the game board to its initial state and returns the updated game board and score as JSON.

Frontend Screenshots

frontend

documentation modal

For more details and examples, please refer to the code and comments in the individual files.

License

This project is licensed under the MIT License.

About

Implementation of 2048 game. This is web application with python backend and (js)jquery and bootstrap frontend.


Languages

Language:Python 63.5%Language:HTML 17.1%Language:JavaScript 11.2%Language:CSS 8.2%