Code Monkey home page Code Monkey logo

letters-game's Introduction

Letters-Cubes Helper

This is a tool to help solve a kids game

In this game, each player roll 7 dices with letters on them, and the goal is to arrange words out of them

Words can be arrange in a row:

use1

We can also arrange them vertically:

use1 use1

The game is over once all the letters has been chosen, each as a part of some word on the board:

use1

Programming tools

To solve this problem I've used the following key ideas:

  • random
    • In the function roll_a_dice(num=7, on=False) which simulate a single dice roll for us
  • combinatorics
    • subset(roll) which generate each possible subset of a givin dice roll
    • every_combination(lists) sorting out the unique subsets
  • dictionary
    • I've created a dictionary for Hebrew words from a file I found online. I'm well aware this dictionary isn't comprehensive nor completely accurate but it's well fitted for the task at hand

Example of usage

In order to run a single turn we'll call the function:

single_turn()

This function simulate a single dice roll, and prints a list of all the Hebrew words we can generate from those letters:

use

After seeing this list, the first player can choose one of the 5 letter words and place it on the board:

use

Thus the second player can choose on of the 3 letter words to place the remaining 2 letters:

use

And the second player would win this round

Game analysis

We can use this code to generate new insights on the game

The main tool I wrote for that is the function analyze_game(times)

This function's input is the number of games we wish to run, and it's output is statistical data gathered from those round

use

From this pie chart we can deduce that it is not so likely to win this game on the first round, the probability of finishing a game in one round is about 10% moreover is it very unlikely that we won't be able to find a word shorter than 5 letters, since for 4 letter the chances are 2.3% and after running 1000 games we can see clearly that it was always possible to find a 4-letter word to place.

  • So the best strategy for the first player would be to place the shortest word, so that the other player wont be able to finish the board
  • While the best strategy second player if to maximize the word he's placing

use

In this bar graph we see the distribution of letters in the lists of words we can create with the dice rolls.

From this we can learn that the best letters for building word are the vowels, which is indeed no surprise

letters-game's People

Contributors

kfirkrak 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.