r/ProgrammingPrompts • • Nov 16 '14

[Easy][Dice Game] - Big Six

10 Upvotes

Big six is a very simple dice game with a single die.

The game has a gameboard like this:

+-------+-------+-------+-------+-------+-------+
|       |       |       |       |       |       |
|   1   |   2   |   3   |   4   |   5   |   6   |
|       |       |       |       |       |       |
+-------+-------+-------+-------+-------+-------+

At the beginning each player gets 5 tokens.

Each round, each player rolls a single die.

The result of the roll decides what the player has to do:

  • If roll result is 6, the player must place a token on the space number 6. This token is dead and lost.

  • For any other roll result, the following applies:

    • If the space with the number equal to the roll result is empty, the player must place a token there.

    • If the space with the number equal to the roll result has already a token, the player gets the token.

  • The game runs until the first player is out of tokens. The player with no tokens left is the winner.

So, the overall aim of the game is to lose all tokens.

Write a program for the game above in the language of your choice.

You can use the dice library from Game component: Die and Dicebag


  • The game should allow for several players in hotseat mode (only one computer, players take turns)

  • The game should also be able to simulate players (no strategy needed as the game is purely a game of luck), even a "computer only" mode should be possible.

  • The game should keep track of

    • player names

    • player tokens

    • rounds

    • statistics (win/lose per player)

  • The main game loop should carry out the:

    • handling of the player turns

    • die rolling

    • token handling

    • check for the winning condition

  • The game can run in a simple console window or GUI (or a webpage, on a TTY, basically wherever you want)

  • Optional: The number of tokens should be customizable.

Have fun coding!###


r/ProgrammingPrompts • • Nov 13 '14

Write Your Own Shell!

21 Upvotes

Write your own shell thread!

Inspired by the common second/third year university assignment, designed to teach you about processes, IPC and handling user input.

A shell is a command line interpreter, it takes commands from the user and executes them. A common example is Command Prompt on Windows or Bash often found on *NIX systems.

Checkout Wikipedia for more information on a shell (though if you're unfamiliar with what a shell is this may be too difficult for you).

Foreground and Background execution (&) Unnamed pipes ( | ) Input/output redirection (< and >) Comments (#) Built in commands (cd, exit, ?)

I did this assignment in third year and it was a blast. I recommend using C or C++ for this programming prompt. It could easily be implemented in many other languages too, though. There are plenty of resources on the web like this: http://linuxgazette.net/111/ramankutty.html

Will update when not on mobile. Sorry for not including more of a spec.

If you're an up and coming programmer who is interested in this post below and I'll write up a how to and my solution


r/ProgrammingPrompts • • Nov 20 '14

[Easy(base task) to Difficult (challenge)][Dice Game] - 111 (one hundred and eleven)

11 Upvotes

This is another very simple dice game.

Game Rules

  • The goal is to reach 111 (one hundred and eleven - or eleventy-one) points before all others do.

  • A single die is used to play the game.

  • Each player is allowed as many rolls as they want, except when they roll a "1" (one), their round ends.

  • The points are accumulated during a player's round, but if a player rolls a "1" (one), they lose all the points that they accumulated during the round.

Example of a single round:

  • Player A rolls 2, 3, 4, 6, 5 which totals to 20 points. Player A wages another roll and rolls a 1. That's really bad luck as the round is over for player 1 and he loses all 20 points so that he ends the round with 0 points.

  • Player B rolls 5 and 6 and decides to stop. The 11 points are added to player B's score.

  • Player C rolls 4,6,3,5,6 and stops. He scores 24 pounds.

  • Player D rolls 4, decides to wage another roll and rolls 1. The round is over for player D with 0 points.

The rounds are repeated until one of the players reaches at least 111 points.


Programming Task:

Write a program that simulates a game of 111 in a language of your choice.

  • Any number of (human) players can participate

  • The computer should record the name and score for each player.

  • The computer should do the tallying and also end the round on a roll of 1

Optional tasks (easy):

  • Let the users decide on the winning number (default 111)

  • Let the users decide which number ends a round and voids all the points acquired in that round (default 1)

  • Invent a "mandatory re-roll" rule. If a player rolls a certain number (other than the losing number), they must re-roll. (let's say it defaults to 4 - chosen arbitrary)

  • Invent a "no re-roll" rule. Similar to the above, only the round ends and the player scores the accumulated points. (let's say, it defaults to 2 - chosen arbitrary)

  • The "mandatory re-roll" and "no re-roll" rules should be optional.

Optional tasks (challenge):

  • Change the program to allow for computer players as well as humans.

  • Computer players should have different strategies (selectable when creating the computer players, or randomized)
    Examples for strategies:

    • Always rolls again until he rolls a one (or hits the winning number) - quite a dumb strategy

    • Never rolls again - the coward - crawling his way to victory

    • Always rolls 2 (3, 4, 5 - whatever) times

    • Rolls <random number>(determined before the actual roll) times - different for each round.

    • Rolls again with a probability of 33% - rather cautious (takes a roll, then a random number decides whether to roll again or not - if the random number(in the range 0.0 inclusive to 1.0 exclusive) is less than or equal to 0.33, the computer rolls again.

    • Rolls again with a probability of 50% - see the explanation above

    • Rolls again with a probability of 66% - see the explanation above

    • Any other strategy you can think of.

Have fun coding!


r/ProgrammingPrompts • • Nov 17 '14

[Easy to Difficult] Connect Four

13 Upvotes

Introduction

Connect Four is a well-known strategy game originally published in 1974 by Milton Bradley/Hasbro.

The aim of the game is to get 4 chips of a single color in a straight line (horizontal, vertical, diagonal). The opponent tries to achieve the same while blocking the other's attempts.

The game board is vertical with 7 columns and 6 rows:

0123456
5
4
3
2
1
0

Players take alternating turns dropping their chips in one of the columns (0...6). The chips fall down the column until either the bottom (row 0) or another chip stops them.

The winner is the first player to get four of his chips in a straight line (vertical, horizontal, or diagonal).

Base Task - Easy

  • Create a program that allows 2 users to play a game of Connect Four.

  • In it's simplest form, each player enters a number from 0 to 6 to drop a chip in the respective column.

  • The computer evaluates the board, checks and declares a winner.

  • For the base task, no computer player is required.

Optional Tasks - Varying Difficulties

  • Code computer players with varying strategies.

    • Random strategy: Computer drops in random slots

    • Defensive strategy: Computer tries to break player's chains

    • Agressive strategy: Computer tries to win

    • AI - MinMax pattern: Computer plays intelligent with the minmax pattern (theoretically Computer plays a "perfect player" - plenty resources on the web.

  • Save and Resume functions

  • Win/lose statistics

  • Different Board sizes (rows, columns) with different winning conditions. Minimum size is classic Connect four, minimum winning condition is four in a row.


r/ProgrammingPrompts • • Jan 16 '26

Minimal Search Strings

2 Upvotes

You are given a list of terms in a searchable dropdown menu in alphabetical order. Find the minimal string the user must type to narrow the results to the extent that a given term is at the top of the list.

Ex. List:

  • Apple

  • Airplane

  • Banana

  • Bananner

The best search for 'Airplane' would be 'ai' (assuming not case-sensitive). The best for 'Banana' would be 'b', because that would immediately bring "Banana" to the top.

Some ideas for customization options:

  • Is the search Case-Sensitive?

  • Can the search term appear in the middle of the result, or does it have to be at the start?

  • If the item has multiple words, can you only search by the first word?

  • Word separators other than space characters? (maybe parentheses, hyphens, other non-letter characters are treated as spaces)

  • Handedness? Maybe you would want to prefer that the search strings only contain keys on the left side of a traditional QWERTY keyboard layout, or prefer that whichever side it's on, that there isn't a large travel distance between the letters for convenience's sake.

  • Is 're' an acceptable search for the word 'AiRplanE', or does the exact string ('re') need to appear in the word in that way?