Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13.7'
python-version: '3.14.0'

- name: Install all dependencies and tools
run: |
Expand All @@ -38,7 +38,7 @@ jobs:
run: pytest || true

- name: Run Ruff checks with ignored rules
run: ruff check . --ignore B904,B905,EM101,EXE001,G004,ISC001,PLC0415,PLC1901,PLW060,PLW1641,PLW2901,PT011,PT018,PT028,S101,S311,SIM905,SLF001
run: ruff check . --ignore B904,B905,EM101,EXE001,G004,ISC001,PLC0415,PLC1901,PLW060,PLW1641,PLW2901,PT011,PT018,PT028,S101,S311,SIM905,SLF001,F405

- name: Run Mypy type checks
run: mypy . --ignore-missing-imports || true
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ for i in string:
odd+=i
print(lower+upper+odd+even)

.vscode
__pycache__/
.venv
# operating system-related files

# file properties cache/storage on macOS
*.DS_Store

# thumbnail cache on Windows
Thumbs.db
bankmanaging.db
3 changes: 2 additions & 1 deletion BoardGame-CLI/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ def play_snakes_and_ladders():


# Start the game
play_snakes_and_ladders()
if __name__ == "__main__":
play_snakes_and_ladders()
5 changes: 3 additions & 2 deletions BoardGame-CLI/snakeLadder.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def play():
elif n == 2:
players = {} # stores player ans their locations
isReady = {}
current_loc = 0 # vaiable for iterating location
current_loc = 1 # reset starting location to 1
player_input()

elif n == 3:
Expand Down Expand Up @@ -170,4 +170,5 @@ def ladder(a, i):
print("/" * 40)


player_input()
if __name__ == "__main__":
player_input()
248 changes: 144 additions & 104 deletions BoardGame-CLI/uno.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# uno game #

import random
from typing import List

"""
Generate the UNO deck of 108 cards.
Parameters: None
Return values: deck=>list

Doctest examples:

>>> deck = buildDeck()
>>> len(deck)
108
>>> sum(1 for c in deck if 'Wild' in c)
8

Return: list of card strings (e.g. 'Red 7', 'Wild Draw Four')
"""


def buildDeck():
deck = []
def buildDeck() -> List[str]:
deck: List[str] = []
# example card:Red 7,Green 8, Blue skip
colours = ["Red", "Green", "Yellow", "Blue"]
values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "Draw Two", "Skip", "Reverse"]
Expand All @@ -24,7 +33,6 @@ def buildDeck():
for i in range(4):
deck.append(wilds[0])
deck.append(wilds[1])
print(deck)
return deck


Expand All @@ -35,10 +43,9 @@ def buildDeck():
"""


def shuffleDeck(deck):
for cardPos in range(len(deck)):
randPos = random.randint(0, 107)
deck[cardPos], deck[randPos] = deck[randPos], deck[cardPos]
def shuffleDeck(deck: List[str]) -> List[str]:
# use Python's built-in shuffle which is efficient and correct
random.shuffle(deck)
return deck


Expand All @@ -48,10 +55,18 @@ def shuffleDeck(deck):
"""


def drawCards(numCards):
cardsDrawn = []
def drawCards(numCards: int) -> List[str]:
"""
Draw a number of cards from the top of the global `unoDeck`.

Raises ValueError if the deck runs out of cards.
"""
cardsDrawn: List[str] = []
for x in range(numCards):
cardsDrawn.append(unoDeck.pop(0))
try:
cardsDrawn.append(unoDeck.pop(0))
except IndexError:
raise ValueError("The deck is empty; cannot draw more cards")
return cardsDrawn


Expand All @@ -62,7 +77,7 @@ def drawCards(numCards):
"""


def showHand(player, playerHand):
def showHand(player: int, playerHand: List[str]) -> None:
print("Player {}'s Turn".format(players_name[player]))
print("Your Hand")
print("------------------")
Expand All @@ -80,7 +95,15 @@ def showHand(player, playerHand):
"""


def canPlay(colour, value, playerHand):
def canPlay(colour: str, value: str, playerHand: List[str]) -> bool:
"""
Return True if any card in playerHand is playable on a discard with given colour and value.

>>> canPlay('Red','5',['Red 3','Green 5'])
True
>>> canPlay('Blue','7',['Green 1'])
False
"""
for card in playerHand:
if "Wild" in card:
return True
Expand All @@ -89,101 +112,118 @@ def canPlay(colour, value, playerHand):
return False


# --- Global deck and initial setup ---
unoDeck = buildDeck()
unoDeck = shuffleDeck(unoDeck)
unoDeck = shuffleDeck(unoDeck)
discards = []
discards: List[str] = []

players_name = []
players = []
players_name: List[str] = []
players: List[List[str]] = []
colours = ["Red", "Green", "Yellow", "Blue"]
numPlayers = int(input("How many players?"))
while numPlayers < 2 or numPlayers > 4:
numPlayers = int(
input("Invalid. Please enter a number between 2-4.\nHow many players?")
)
for player in range(numPlayers):
players_name.append(input("Enter player {} name: ".format(player + 1)))
players.append(drawCards(5))


playerTurn = 0
playDirection = 1
playing = True
discards.append(unoDeck.pop(0))
splitCard = discards[0].split(" ", 1)
currentColour = splitCard[0]
if currentColour != "Wild":
cardVal = splitCard[1]
else:
cardVal = "Any"

while playing:
showHand(playerTurn, players[playerTurn])
print("Card on top of discard pile: {}".format(discards[-1]))
if canPlay(currentColour, cardVal, players[playerTurn]):
cardChosen = int(input("Which card do you want to play?"))
while not canPlay(
currentColour, cardVal, [players[playerTurn][cardChosen - 1]]
):
cardChosen = int(input("Not a valid card. Which card do you want to play?"))
print("You played {}".format(players[playerTurn][cardChosen - 1]))
discards.append(players[playerTurn].pop(cardChosen - 1))

# cheak if player won
if len(players[playerTurn]) == 0:
playing = False
# winner = "Player {}".format(playerTurn+1)
winner = players_name[playerTurn]
else:
# cheak for special cards
splitCard = discards[-1].split(" ", 1)
currentColour = splitCard[0]
if len(splitCard) == 1:
cardVal = "Any"
else:
cardVal = splitCard[1]
if currentColour == "Wild":
for x in range(len(colours)):
print("{}) {}".format(x + 1, colours[x]))
newColour = int(input("What colour would you like to choose? "))
while newColour < 1 or newColour > 4:
newColour = int(
input("Invalid option. What colour would you like to choose")
)
currentColour = colours[newColour - 1]
if cardVal == "Reverse":
playDirection = playDirection * -1
elif cardVal == "Skip":
playerTurn += playDirection
if playerTurn >= numPlayers:
playerTurn = 0
elif playerTurn < 0:
playerTurn = numPlayers - 1
elif cardVal == "Draw Two":
playerDraw = playerTurn + playDirection
if playerDraw == numPlayers:
playerDraw = 0
elif playerDraw < 0:
playerDraw = numPlayers - 1
players[playerDraw].extend(drawCards(2))
elif cardVal == "Draw Four":
playerDraw = playerTurn + playDirection
if playerDraw == numPlayers:
playerDraw = 0
elif playerDraw < 0:
playerDraw = numPlayers - 1
players[playerDraw].extend(drawCards(4))
print("")


def main() -> None:
"""Run interactive UNO game (keeps original behavior).

Note: main() is interactive and not exercised by doctest.
"""
global players_name, players, discards

numPlayers = int(input("How many players?"))
while numPlayers < 2 or numPlayers > 4:
numPlayers = int(
input("Invalid. Please enter a number between 2-4.\nHow many players?")
)
for player in range(numPlayers):
players_name.append(input("Enter player {} name: ".format(player + 1)))
players.append(drawCards(5))

playerTurn = 0
playDirection = 1
playing = True
discards.append(unoDeck.pop(0))
splitCard = discards[0].split(" ", 1)
currentColour = splitCard[0]
if currentColour != "Wild":
cardVal = splitCard[1]
else:
print("You can't play. You have to draw a card.")
players[playerTurn].extend(drawCards(1))
cardVal = "Any"

while playing:
showHand(playerTurn, players[playerTurn])
print("Card on top of discard pile: {}".format(discards[-1]))
if canPlay(currentColour, cardVal, players[playerTurn]):
cardChosen = int(input("Which card do you want to play?"))
while not canPlay(
currentColour, cardVal, [players[playerTurn][cardChosen - 1]]
):
cardChosen = int(
input("Not a valid card. Which card do you want to play?")
)
print("You played {}".format(players[playerTurn][cardChosen - 1]))
discards.append(players[playerTurn].pop(cardChosen - 1))

# cheak if player won
if len(players[playerTurn]) == 0:
playing = False
# winner = "Player {}".format(playerTurn+1)
winner = players_name[playerTurn]
else:
# cheak for special cards
splitCard = discards[-1].split(" ", 1)
currentColour = splitCard[0]
if len(splitCard) == 1:
cardVal = "Any"
else:
cardVal = splitCard[1]
if currentColour == "Wild":
for x in range(len(colours)):
print("{}) {}".format(x + 1, colours[x]))
newColour = int(input("What colour would you like to choose? "))
while newColour < 1 or newColour > 4:
newColour = int(
input(
"Invalid option. What colour would you like to choose"
)
)
currentColour = colours[newColour - 1]
if cardVal == "Reverse":
playDirection = playDirection * -1
elif cardVal == "Skip":
playerTurn += playDirection
if playerTurn >= numPlayers:
playerTurn = 0
elif playerTurn < 0:
playerTurn = numPlayers - 1
elif cardVal == "Draw Two":
playerDraw = playerTurn + playDirection
if playerDraw == numPlayers:
playerDraw = 0
elif playerDraw < 0:
playerDraw = numPlayers - 1
players[playerDraw].extend(drawCards(2))
elif cardVal == "Draw Four":
playerDraw = playerTurn + playDirection
if playerDraw == numPlayers:
playerDraw = 0
elif playerDraw < 0:
playerDraw = numPlayers - 1
players[playerDraw].extend(drawCards(4))
print("")
else:
print("You can't play. You have to draw a card.")
players[playerTurn].extend(drawCards(1))

playerTurn += playDirection
if playerTurn >= numPlayers:
playerTurn = 0
elif playerTurn < 0:
playerTurn = numPlayers - 1

print("Game Over")
print("{} is the Winner!".format(winner))

playerTurn += playDirection
if playerTurn >= numPlayers:
playerTurn = 0
elif playerTurn < 0:
playerTurn = numPlayers - 1

print("Game Over")
print("{} is the Winner!".format(winner))
if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions Industrial_developed_hangman/tests/test_hangman/test_main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os
from pathlib import Path
from typing import Callable, List

import pytest
Expand All @@ -8,7 +6,6 @@
from src.hangman.main import (
MainProcess,
Source,
parse_word_from_local,
parse_word_from_site,
)

Expand Down
Loading
Loading