Skip to content

Commit 164692a

Browse files
Merge pull request #916 from amjadkofahi/sourcery/main
Sourcery/main
2 parents 686fbdf + a20b3ff commit 164692a

File tree

74 files changed

+609
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+609
-848
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ venv/
3737
**/*.rs.bk
3838
/target
3939
todo.md
40+
41+
.fake
42+
.fake

00_Alternate_Languages/89_Tic-Tac-Toe/MiniScript/README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ Conversion to [MiniScript](https://miniscript.org).
55
Ways to play:
66

77
1. Command-Line MiniScript:
8-
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
8+
Download for your system from <https://miniscript.org/cmdline/>, install, and then run the program with a command such as:
9+
910
```
10-
miniscript tictactoe.ms
11+
miniscript tictactoe.ms
1112
```
1213

1314
2. Mini Micro:
14-
Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the MiniScript program and this README file. Then, at the Mini Micro command prompt, enter:
15+
Download Mini Micro from <https://miniscript.org/MiniMicro/>, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the MiniScript program and this README file. Then, at the Mini Micro command prompt, enter:
16+
17+
```
18+
load "tictactoe"
19+
run
1520
```
16-
load "tictactoe"
17-
run
18-
```

02_Amazing/python/amazing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def display(self) -> None:
4747
print(" ", end="")
4848
print()
4949
for col in range(self.width):
50-
if self.walls[row][col] == 0 or self.walls[row][col] == 2:
50+
if self.walls[row][col] in [0, 2]:
5151
print(":--", end="")
5252
else:
5353
print(": ", end="")
@@ -148,7 +148,7 @@ def make_opening(
148148
maze.walls[pos.row][pos.col] = maze.walls[pos.row][pos.col] + EXIT_DOWN
149149
pos.row = pos.row + 1
150150
maze.used[pos.row][pos.col] = count
151-
count = count + 1
151+
count += 1
152152
return pos, count
153153

154154

03_Animal/python/animal.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,13 @@ def parse_input(message: str, check_list: bool, root_node: Optional[Node]) -> st
104104
list_known_animals(root_node)
105105
print("\n")
106106

107-
if len(inp) > 0:
108-
token = inp[0].lower()
109-
else:
110-
token = ""
111-
107+
token = inp[0].lower() if len(inp) > 0 else ""
112108
return token
113109

114110

115111
def avoid_void_input(message: str) -> str:
116112
answer = ""
117-
while answer == "":
113+
while not answer:
118114
answer = input(message)
119115
return answer
120116

@@ -134,8 +130,12 @@ def main() -> None:
134130

135131
# Main loop of game
136132
print_intro()
137-
keep_playing = parse_input("Are you thinking of an animal? ", True, root) == "y"
138-
while keep_playing:
133+
while (
134+
keep_playing := parse_input(
135+
"Are you thinking of an animal? ", True, root
136+
)
137+
== "y"
138+
):
139139
keep_asking = True
140140
# Start traversing the tree by the root
141141
actual_node: Node = root
@@ -170,17 +170,13 @@ def main() -> None:
170170
f"for a {new_animal} the answer would be: ", False, None
171171
)
172172

173-
actual_node.update_node(
174-
new_question + "?", answer_new_question, new_animal
175-
)
173+
actual_node.update_node(f"{new_question}?", answer_new_question, new_animal)
176174

177175
else:
178176
print("Why not try another animal?")
179177

180178
keep_asking = False
181179

182-
keep_playing = parse_input("Are you thinking of an animal? ", True, root) == "y"
183-
184180

185181
########################################################
186182
# Porting Notes

04_Awari/python/awari.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@
8383

8484
def draw_pit(line: str, board, pit_index) -> str:
8585
val = board[pit_index]
86-
line = line + " "
86+
line += " "
8787
if val < 10:
88-
line = line + " "
89-
line = line + str(val) + " "
90-
return line
88+
line += " "
89+
return line + str(val) + " "
9190

9291

9392
def draw_board(board) -> None:
@@ -148,7 +147,7 @@ def play_game(board: List[int]) -> None:
148147
print(msg)
149148
break
150149
if landing_spot == home:
151-
landing_spot, is_still_going, home, msg = computer_move(msg + " , ", board)
150+
landing_spot, is_still_going, home, msg = computer_move(f"{msg} , ", board)
152151
if not is_still_going:
153152
print(msg)
154153
break
@@ -248,7 +247,7 @@ def computer_move(msg: str, board) -> Tuple[int, bool, int, str]:
248247

249248
move_str = chr(42 + selected_move)
250249
if msg:
251-
msg += ", " + move_str
250+
msg += f", {move_str}"
252251
else:
253252
msg = move_str
254253

@@ -323,10 +322,7 @@ def execute_move(move, home: int, board) -> Tuple[int, bool, int]:
323322
# losses.
324323
losing_book[game_number] = losing_book[game_number] * 6 + move_digit
325324

326-
if player_has_stones(board) and computer_has_stones(board):
327-
is_still_going = True
328-
else:
329-
is_still_going = False
325+
is_still_going = bool(player_has_stones(board) and computer_has_stones(board))
330326
return last_location, is_still_going, home
331327

332328

05_Bagels/python/bagels.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def pick_number() -> List[str]:
4949
# as separate strings, not a single integer or string
5050
numbers = list(range(10))
5151
random.shuffle(numbers)
52-
num = numbers[0:3]
53-
num_str = [str(i) for i in num]
54-
return num_str
52+
num = numbers[:3]
53+
return [str(i) for i in num]
5554

5655

5756
def get_valid_guess(guesses: int) -> str:

06_Banner/python/banner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ def print_banner() -> None:
7474

7575
except ValueError:
7676
print("Please enter a number greater than zero")
77-
g1 = 0
78-
if input("Centered ").lower().startswith("y"):
79-
g1 = 1
77+
g1 = 1 if input("Centered ").lower().startswith("y") else 0
8078
character = input(
8179
"Character (type 'ALL' if you want character being printed) "
8280
).upper()
@@ -87,7 +85,7 @@ def print_banner() -> None:
8785
for statement_char in statement:
8886
s = letters[statement_char].copy()
8987
x_str = character
90-
if character == "ALL":
88+
if x_str == "ALL":
9189
x_str = statement_char
9290
if x_str == " ":
9391
print("\n" * (7 * horizontal))

0 commit comments

Comments
 (0)