Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3cdc106

Browse files
Merge pull request avinashkranjan#2654 from andoriyaprashant/branch29
Pattern Recognition Game Script Added
2 parents 2b503c4 + 8f9822f commit 3cdc106

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

‎Pattern Recognition Game/README.md‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Pattern Recognition Game
2+
3+
## Introduction
4+
Welcome to the Pattern Recognition Game! This is a text-based game where players are presented with sequences of color patterns and have to identify the underlying rule to predict the next pattern in the series.
5+
6+
## Rules
7+
- The game will present you with a sequence of colors in a pattern.
8+
- Your task is to figure out the underlying rule that governs the pattern and determine the next color in the sequence.
9+
- For each round, you will have a limited number of attempts to guess the correct next pattern.
10+
- If you guess the correct pattern, you score a point and move on to the next round. Otherwise, the game ends.
11+
12+
## Features
13+
- Randomly generated color patterns.
14+
- Timer: A time limit will be set for each round, and you must make your guess before time runs out.
15+
- Levels: As you progress and score higher, the game will introduce higher levels of difficulty with longer patterns.
16+
- Hint System: You have the option to use hints that reveal the next color in the sequence (limited number of hints available).
17+
- Various colors and patterns for a diverse gaming experience.
18+
19+
## Installation
20+
1. Make sure you have Python installed on your system.
21+
2. Clone or download this repository to your local machine.
22+
3. Open a terminal or command prompt and navigate to the game's directory.
23+
24+
## How to Play
25+
1. Run the game by executing the following command:
26+
27+
```bash
28+
python pattern_recognition_game.py
29+
```
30+
31+
2. Follow the on-screen instructions and enter your answers accordingly.
32+
3. Try to guess the correct next pattern within the given time limit to score points and progress through the game.
33+
34+
## Requirements
35+
- Python
36+
37+
## Contributing
38+
If you have any ideas for improving the game or implementing new features, feel free to fork this repository and create a pull request. Your contributions are welcome!
39+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import random
2+
import time
3+
4+
def generate_pattern():
5+
colors = ["red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "black", "white", "cyan", "magenta"]
6+
patterns = [
7+
["red", "green", "blue", "yellow", "orange"],
8+
["purple", "pink", "brown", "gray", "black"],
9+
["white", "cyan", "magenta", "red", "blue", "green"],
10+
["brown", "gray", "pink", "red", "blue"],
11+
["yellow", "orange", "red", "purple"],
12+
["white", "gray", "black", "pink", "cyan", "blue"],
13+
["yellow", "green", "orange", "blue"],
14+
["magenta", "purple", "green", "cyan", "yellow"],
15+
["red", "green", "blue", "yellow", "orange", "purple", "pink"],
16+
["red", "blue", "orange", "yellow", "cyan", "magenta"],
17+
["blue", "green", "yellow", "orange", "brown"],
18+
["cyan", "magenta", "yellow", "gray", "purple"],
19+
["red", "green", "blue", "yellow", "orange", "purple", "pink", "cyan"],
20+
["blue", "red", "green", "yellow", "orange", "purple", "brown", "cyan"],
21+
["magenta", "purple", "pink", "yellow", "orange", "green", "red", "gray"]
22+
]
23+
pattern = random.choice(patterns)
24+
return pattern
25+
26+
def get_next_pattern(pattern):
27+
colors = set(["red", "green", "blue", "yellow", "orange", "purple", "pink", "brown", "gray", "black", "white", "cyan", "magenta"])
28+
pattern_set = set(pattern)
29+
missing_color = list(colors - pattern_set)[0]
30+
next_pattern = pattern[1:] + [missing_color]
31+
return next_pattern
32+
33+
def play_game():
34+
print("Welcome to the Pattern Recognition Game!")
35+
print("Try to identify the underlying rule of the color patterns.")
36+
print("For example, if the pattern is ['red', 'green', 'blue', 'yellow', 'orange'], the next pattern will be ['green', 'blue', 'yellow', 'orange', 'purple'] (alphabetical order).\n")
37+
38+
score = 0
39+
max_attempts = 3
40+
hint_limit = 1
41+
time_limit = 20
42+
43+
while True:
44+
pattern = generate_pattern()
45+
print("Pattern:", pattern)
46+
47+
for attempt in range(max_attempts):
48+
user_input = input("Enter the next pattern: ").split()
49+
50+
if user_input == get_next_pattern(pattern):
51+
score += 1
52+
print("Correct!")
53+
break
54+
else:
55+
print(f"Wrong! {max_attempts - attempt - 1} attempts remaining.")
56+
57+
else:
58+
print(f"\nGame Over! Your score: {score}\n")
59+
break
60+
61+
# Give the player a hint option
62+
if hint_limit > 0:
63+
hint_choice = input("Would you like a hint? (yes/no): ").lower()
64+
if hint_choice == "yes":
65+
hint_limit -= 1
66+
print("Hint: The next color is", get_next_pattern(pattern)[-1])
67+
68+
# Introduce levels based on the score
69+
if score >= 5:
70+
max_attempts = 2
71+
if score >= 10:
72+
time_limit = 15
73+
74+
# Timer implementation
75+
start_time = time.time()
76+
while time.time() - start_time < time_limit:
77+
pass
78+
print("\nTime's up!\n")
79+
print(f"Your score: {score}\n")
80+
81+
if __name__ == "__main__":
82+
play_game()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
random

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /