Giter Site home page Giter Site logo

2048-python's Introduction

2048-python

This is my 2048 puzzle AI module written in python for an office fun event.

The time limit of every move is 0.1 seconds.

Variants

There are five variants:

  • kcwu.py Normal version.
  • kcwu2.py Based on kcwu.py, multi-process.
  • kcwu_short.py Based on kcwu.py, optimized for maximize (average_score/code_size).
  • kcwu_short2.py Based on kcwu2.py, optimized for maximize (average_score/code_size).
  • kcwu_short_min.py Optimized for minimize (average_score*code_size).

Algorithm

  • Search: expectiminimax. It can search 3 steps ahead using expectiminimax.
  • Eval: inspired from the stackoverflow article, combined with monotoneness, smoothness, and number of blank tile.
    • Weighting of these scores are tuned by hand. I don't know the reason of those magic numbers ;)
  • Optimization:
    • Cut some 4 tile since the probability is low
    • Caching score for search node and eval node.
    • Because python is slow, I put some efforts to optimize for speed and the code is then ugly.

Test result

Result of 100 runs (single thread version):

  • average 85458
  • median 79396
  • max 175484
  • average speed: 17 ms/step

License and copyright

BSD license. The copyright is owned by Google Inc. but this is not official product.

2048-python's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

2048-python's Issues

Not able to create an instance of AI class in multi processing mode

I am trying to use a part of your code and i was stuck at an Error:
TypeError:
Traceback (most recent call last)
in ()
35 return grid
36
---> 37 ai = AI()

in build_move_table(self)
140 row_moved = tuple(move_row(row))
--> 142 if max(row_moved) > max_cell:
143 self.move_table[idx] = -1
144 else:

TypeError: '>' not supported between instances of 'NoneType' and 'int'

python version?

Is this written by Python2.7? Because I run it on my python3.9, there are many warnings.

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.