Dice Cricket is a game I was introduced to as a child and have used as a way to pass time for years since. I couldn't find a Wikipedia page so I'll explain the rules below.

Dice Cricket Rules


Dice Cricket is a game similar to scoring a game of cricket as you watch it but rather than watching and recording the result, you are rolling a die and recording the result.

The results are recorded in a table as displayed at the bottom.


Dice Cricket uses a specific display to show all the information happening.

The table has 11 rows. Each row represents a batter. The layout of the row is explained below.

| Name |    Runs                      | How Out |Score|
  • Name: The name must be a string made up entirely of letters, upper or lower case
  • Runs: A batter can face 30 balls. Each ball can be one of 1 2 4 6 . /. This will be explained in more detail below
  • How Out: The way the batter was out. Can be any of Bowled, LBW (Leg Before Wicket), Caught, Retired or Not Out
  • Score: The sum of all numbers in Runs

How the Game Works

In a game, there are always 2 batters out on the pitch. The first player is by default the current batter and the second in the "off" batter.

A game is made up of "balls": each ball in a cricket match is represented by a dice roll. Each roll does a different command:

  • 1,2,4 and 6 make the batter score that much. If 1 is rolled, the current batter becomes the "off" batter and the "off" batter becomes the current
  • 3 is a "dot ball", meaning that nothing happens. It is represented in the Runs section as a . and scores 0. A 0 may not be used to represent it.
  • 5 is a wicket. If 5 is rolled, the current batter is "out", This means that a / is added to the runs and from then on, the batter cannot score anymore runs. The batter is then swapped with the next batter who has not batted. The How Out section is a random choice of the possible ways to get out: Bowled, LBW, Caught

Example for a wicket (this is just for clarity, this isn't how its outputted)

player a is on 4,6,2,6,4
player b is on 6,4,2,6,6
player c hasn't batted
player a is current batter


player a is on 4,6,2,6,4,/
player b in on 6,4,2,6,6
player c is on NOTHING
player c is current batter

Every 6 balls, the two batters switch; the current batter becomes the "off" batter and the "off" batter becomes the current batter

If the Runs section is filled (30 balls), the batter is out and the How Out section is set to Retired. A / isn't placed at the end of the Runs box.

Actual Challenge (yes all that was rules of the game)

Your challenge is to output a completed table (like the example at the end), given a list of names. The contents of the output should contain only the table and/or leading or trailing whitespace.


  • Standard loopholes are disallowed
  • All 11 players should have something in the Runs section.
  • Only 1 player can be Not Out. Every other non-retired player should be out of a choice of [Bowled, LBW, Caught]
  • The names can be any length between 1 and 6 that matches the regex A-Za-z
  • The final line in the table should be the total line (see example)
  • You don't have to align the text in the table in any way, but the row and column separators must be aligned.


['Fred', 'Sonya', 'David', 'Ben', 'Cody', 'Hazel', 'Nina', 'Kim', 'Cath', 'Lena', 'Will']
| Name | Runs                         | How Out |Total|
|Fred  |.662/                         | Caught  | 14  |
|Sonya |1164/                         | Caught  | 12  |
|David |/                             |   LBW   |  0  |
|Ben   |424/                          |   LBW   | 10  |
|Cody  |62/                           | Bowled  |  8  |
|Hazel |/                             |   LBW   |  0  |
|Nina  |161.6226166..44261442/        | Caught  | 64  |
|Kim   |11/                           | Caught  |  2  |
|Cath  |6.21/                         |   LBW   |  9  |
|Lena  |/                             | Bowled  |  0  |
|Will  |2                             | Not Out |  2  |
|               Total Runs                      | 121 |
  • \$\begingroup\$ Sandbox \$\endgroup\$ Commented Dec 14, 2017 at 18:00
  • \$\begingroup\$ Heh, I used to play a similar variant of this called "Hand cricket". \$\endgroup\$ Commented Dec 14, 2017 at 18:43
  • \$\begingroup\$ What determines when the game ends? Is it when a batter is out and there is no one left to replace him? \$\endgroup\$
    – KSmarts
    Commented Dec 14, 2017 at 19:40
  • \$\begingroup\$ @KSmarts Correct. \$\endgroup\$ Commented Dec 14, 2017 at 19:55
  • 1
    \$\begingroup\$ @JonathanAllan Yeah, it isn't a good requirement. Removed \$\endgroup\$ Commented Dec 14, 2017 at 20:05

2 Answers 2


Python 3, 650 621 582 572 588 bytes

from random import*
b=lambda x,r=6:x.ljust(r,' ')
t=lambda a:sum(map(int,a[:-1].replace(*'.0')))
def s(i=30):
 while i:x=choice('12.4/6');yield x;i=('/'!=x)*~-i
def f(n,T=0):
 P(a+f'| Name | Runs{" "*25}| How Out |Total|')
 for x in n[:-1]:S=j(s());T+=t(S);P(a,x,b(S,30),c(choice(['Bowled','LBW','Caught']),9),c(h(t(S)),5),sep='|',end='|\n')
 S=j(s());P(a,n[-1],b(S,30),' Not Out ',c(h(t(S)),5),sep='|',end='|\n');P(a+f'|{15*" "}Total Runs{15*" "}       |{c(h(T),5)}|\n+{47*"-"}+{5*"-"}+')

Try it online!

Well, it's been over 24 hours and this took me about an hour to whip up, so I hope I'm not FGITW'ing anyone, and I haven't golfed in Python in a while, so this was fun (although this is the second time I've answered one of my own questions with a long Python answer)

Please feel free to post golf suggestions, Python isn't my best language for golfing.

-68 bytes thanks to FlipTack!

-8 bytes thanks to Mr. Xcoder

+16 bytes due to a bug

  • \$\begingroup\$ At first glance, I can see quite a few golfs... 1) In one instance you still use print instead of P. 2) sum can directly take a map object, no need to convert it to a list. 3) Rather than writing yield x twice, why not yield x and then break if necessary? 4) T=0 could be placed inside the function header. 5) In your last function, you've used several newlines where you could just use one line with semicolons, for example the first three statements, the last three statements, and the statements in the for loop. \$\endgroup\$
    – FlipTack
    Commented Dec 17, 2017 at 9:41
  • \$\begingroup\$ @FlipTack Nice golfs, and thanks! \$\endgroup\$ Commented Dec 18, 2017 at 15:50
  • \$\begingroup\$ You can golf s considerably... def s(i=30): and then while i:x=choice('12.4/6');yield x;i=('/'!=x)*~-i. Also, you only call o() once, so there's no need to even declare it, just use the statement directly. \$\endgroup\$
    – FlipTack
    Commented Dec 18, 2017 at 17:14
  • \$\begingroup\$ The same applies to b ^^ \$\endgroup\$
    – FlipTack
    Commented Dec 18, 2017 at 17:24
  • \$\begingroup\$ @FlipTack Added the golfs. Thanks! \$\endgroup\$ Commented Dec 19, 2017 at 15:42

Charcoal, 277 255 bytes


Try it online! Link is to verbose version of code. Explanation:


Read in the 11 names (input is flexible: JSON, space separated, or newline separated) and create an array q of 11 batters, represented by their balls (as an array), status (as an integer) and name.


Create a reversed copy of the batters h. This represents the batters that are not out. The last two elements are the off and current batters.


Repeat while there are at least two batters available.


Extract the current batter to i.


Generate a random ball in z.


Add it to the overall list of balls using the predefined empty list u.


Add it to the current batter's balls.


If the ball is a /, then generate a random status 2..4, otherwise if this is the batter's 30th ball then set the status to 1 otherwise 0.


If the batter is out then store the batter's status otherwise put the batter back in to bat.


If there are at least two batters left, and the batter was out xor 6 balls have been played, then...


...take the off and current batters and put them back in reverse order.


Print the header.


Loop over the batters.


Print the batter's name.


Print the batter's balls.


Print the batter's status by indexing into the string Not OutRetiredBowled Caught LBW split into substrings of length 7.


Print the batter's score.


Move to the start of the next line but one.


Print the total.


Draw boxes around everything.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.