Skip to content

Commit 264bc7a

Browse files
committed
add script for progression game, add draft of the progression game, add constant for progression game
1 parent 0e4b1d0 commit 264bc7a

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

brain_games/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
GCD_GAME_INTRODUCTION = [
1313
'Find the greatest common divisor of given numbers.'
1414
]
15+
PROG_GAME_INTRODUCTION = [
16+
'What number is missing in the progression?'
17+
]
1518

1619

1720
GAMES_TO_WIN = 3
1821
MATH_SYMBOLS = ['+', '-', '*']
22+
STEP_OF_SEQUENCE = [2, 3, 4, 5]

brain_games/games/progression.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import random
2+
3+
from brain_games.game_engine import game_engine
4+
from brain_games.constants import STEP_OF_SEQUENCE
5+
from brain_games.constants import PROG_GAME_INTRODUCTION
6+
7+
8+
def get_random_sequence_and_answer():
9+
sequence = []
10+
random_step = random.choice(STEP_OF_SEQUENCE)
11+
12+
for i in range(8):
13+
if i == 0:
14+
sequence.append(random.randint(1, 16))
15+
else:
16+
sequence += [sequence[i-1] + random_step]
17+
18+
question = ''
19+
answer = random.choice(sequence)
20+
21+
for i in range(len(sequence)):
22+
if sequence[i] == answer:
23+
question += ' ..'
24+
else:
25+
question += ' ' + str(sequence[i])
26+
27+
return question.strip(), str(answer)
28+
29+
30+
def progression_game():
31+
game_engine(get_random_sequence_and_answer, PROG_GAME_INTRODUCTION)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python3
2+
3+
from brain_games.games.progression import progression_game
4+
5+
6+
def main():
7+
progression_game()
8+
9+
10+
if __name__ == '__main__':
11+
main()

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ brain-games = "brain_games.scripts.brain_games:main"
1717
brain-even = "brain_games.scripts.brain_even:main"
1818
brain-calc = "brain_games.scripts.brain_calc:main"
1919
brain-gcd = "brain_games.scripts.brain_gcd:main"
20+
brain-prog = "brain_games.scripts.brain_progression:main"
2021

2122
[tool.poetry.group.dev.dependencies]
2223
flake8 = "^7.1.1"

0 commit comments

Comments
 (0)