Python and cubes

The idea

I thought somehow to write something on the "snake" ... Something interesting. The last little project was called Blackjack and was borrowed from one Python training site.

This project should be its own notion written in Python, moreover, a game. I did not want to spend time and write something that would devour its gigantic amount. Therefore, I decided to focus on the simple - on the “cubes”.


The essence of the game is this: you and the opponent (casino dealer), at first you choose a “loan” for yourself, that is, the amount that will be in your virtual “pocket”. Bets are placed in a common “bank”. This is followed by bets and dice rolls. You and your opponent successively roll two dice and the “pot” goes to the one with the most points. If the same amount falls, you and the opponent roll the dice again. The point is simple.

Software implementation

Well, first, we’ll run the help:

b - bet (bet);
c - credit (credit);
t - throw of cubes (throw);

Next, open Anaconda and start writing code:

# #  # import random import sys def help(): print("\n ") print("b -  ;") print(" -  ;") print("t -  ;") credit = 0 bank = 0 bet = int(0) print("      h") while True: print("\n: ", credit) print(": ", bet) command = input(" : ") if command == 'x': sys.exit() elif command == 'h': help() elif command == 'c': credit = input("  : ") credit = int(credit) print("  : ", credit,"$") elif command == 'b': bet = input(" : ") bet = int(bet) if bet > credit: print("   .") bet = 0 else: credit = credit - bet elif command == 't': if bet == 0: print(" .") else: val1 = random.randrange(1,6) val2 = random.randrange(1,6) sum1 = val1 + val2 print("\n  1: ",sum1) val1 = random.randrange(1,6) val2 = random.randrange(1,6) sum2 = val1 + val2 print("  2: ",sum2) if sum1 == sum2: print("  .") elif sum1 > sum2: credit = credit + bet * 2 bet = 0 print("\n !") elif sum1 < sum2: bet = 0 print("\n ...") else: print("\n ") 

Yes, yes, it’s not perfect - there is something that can be “finished off with a file” ... But, as Vovka from the far-away kingdom said:


And then I decided to check out, really "Mona", playing on one simple tactics:

  1. We put 100;
  2. If the bet wins, we bet one hundred again. If loses, we bet twice as much. Go to + ?!

Started with a thousand:


And put a hundred:


And, strangely enough, from 1000 he increased the capital to 2700! - Works!

The system is working. But it works with a random distribution (and not “finished” in favor of “know whom”). Something like this. I hope you will not throw tomatoes!

PS Games are cool! A small piece of childhood, torn from time.


All Articles