Coder Social home page Coder Social logo

py2048's Introduction

2048 Game Simulation in Python

Description

This is my 2048 game simulation in Python. To play the original game, click here. This code can also be used to strenghten some basic concepts of Python for beginners. Do feel free to let me know your feedback through the comments section. Thanks!

Compatibility

This code has been developed and tested well in Windows in the Jupyter Notebook environment (specifically, the Anaconda distribution).

Instructions

  • If you would like to run the code in a Jupyter Notebook, CoLab, or similiar, download the py2048.ipynb version and run it on your environment of choice.
  • If you would like to run it directly in your terminal, download the py2048.py version and run it from terminal. Note that this has clear_screen() functionality disabled since it does not work in terminal.
  • If you would like to run it on an android device's mobile browser or without any prior installation of python environments on a laptop or PC, the code will also work well in Google's CoLab environment. Click here to view and run my code in the CoLab environment. You may provide your comments there as well.

Game Navigation

First, enter the size of the board. For example, if you want to play on a 3x3 board, enter 3.

Next, enter the winning value, which is the value at which you would win if you add up to it. Remember that it should be a power of 2.

Note: The default board size is 5 and win value is 2048. This is set incase of an invalid entry of either of the two respectively.

Now, you may enter your move. To make a move, press either of the WASD keys, or press 'x' to stop the game, 'r' to clear the board or 'g' to restart the entire game. You may do the aforementioned in CAPS LOCK as well.

The game will stop by itself if the win value is identified in the board or if further valid moves are not possible. You will recieve your game stats at the end too !

Special Notes:

  1. The program will randomly spawn a 2 or a 4 after every valid move if the board size is 5 or above. For values, lesser than 5, it would spawn only one 2.
  2. Hidden developer option ! Press capital 'Z' at any point in the game to fill the empty spots of the board with just one entry. The spots would be filled randomly with a 2 or a 4 in accordance with the previous point. This is to test the game overall, but more specifically, the move(<parameters>) function. Note that this will increment the moves_count and attempts variable by just one irrespective of number of spaces automatically filled by the function.

Demonstration

Here's a simple demonstration of the game in .gif format.

py2048's People

Contributors

luqmanfarooqui avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.