Compare commits
23 Commits
be479d2c63
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c2535274d | |||
| f03e390fa4 | |||
| 98a24a92cb | |||
| 470d4b0b2b | |||
| 34e88112c6 | |||
| 864d07348d | |||
| a30e9b2556 | |||
| 6949336bbe | |||
| 33e75d0529 | |||
| f0dda78b43 | |||
| e613278fa2 | |||
| 1b7352680b | |||
| deba677725 | |||
| 8dc989a0a8 | |||
| 5e3b122ab1 | |||
| 6c2d865d96 | |||
| 98a59532da | |||
| 2f6dd3858c | |||
| d4b6db8edf | |||
| 9ca023025b | |||
| 97bdfd1907 | |||
| ee4da2417d | |||
| 8a232759f6 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
|||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.14 (test)" />
|
<option name="sdkName" value="Python 3.14 (test)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14 (test)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.14" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
2
.idea/test.iml
generated
2
.idea/test.iml
generated
@@ -4,7 +4,7 @@
|
|||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="jdk" jdkName="Python 3.14 (test)" jdkType="Python SDK" />
|
<orderEntry type="jdk" jdkName="Python 3.14" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,3 +1,10 @@
|
|||||||
|
######################################
|
||||||
|
# DCS 229 -- Unfair Solitaire
|
||||||
|
# This is the Card.py file, which defines the Card class used in the Solitaire game. The Card class represents a playing card with a suit and value, and includes methods to retrieve the suit and value, as well as a string representation of the card.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
class Card:
|
class Card:
|
||||||
"""
|
"""
|
||||||
Represents a playing card with a suit and value.
|
Represents a playing card with a suit and value.
|
||||||
@@ -20,3 +27,17 @@ class Card:
|
|||||||
return f"{self._value} of {self._suit}"
|
return f"{self._value} of {self._suit}"
|
||||||
|
|
||||||
#Returns a string representation of the card in the format "Value of Suit".
|
#Returns a string representation of the card in the format "Value of Suit".
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
card1 = Card("Hearts", "Ace")
|
||||||
|
card2 = Card("Spades", "10")
|
||||||
|
|
||||||
|
assert card1.get_suit() == "Hearts"
|
||||||
|
assert card1.get_value() == "Ace"
|
||||||
|
assert card2.get_suit() == "Spades"
|
||||||
|
assert card2.get_value() == "10"
|
||||||
|
|
||||||
|
assert repr(card1) == "Ace of Hearts"
|
||||||
|
assert repr(card2) == "10 of Spades"
|
||||||
|
|
||||||
|
print("All Card tests passed.")
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
######################################
|
||||||
|
# DCS 229 -- Unfair Solitaire
|
||||||
|
# This is the Deck.py file, which defines the Deck class used in the Solitaire game. The Deck class represents a standard 52-card deck, and includes methods to shuffle the deck, deal cards, and check the number of remaining cards.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from Card import Card
|
from Card import Card
|
||||||
|
|
||||||
@@ -19,12 +27,18 @@ class Deck:
|
|||||||
self._cards.append(Card(suit, value)) #creates a standard 52-card deck
|
self._cards.append(Card(suit, value)) #creates a standard 52-card deck
|
||||||
|
|
||||||
def shuffle(self):
|
def shuffle(self):
|
||||||
|
"""
|
||||||
|
Shuffles the deck of cards using the Fisher-Yates algorithm. This algorithm iterates through the deck and swaps each card with a randomly selected card from the remaining unshuffled portion of the deck. After shuffling, it resets the next card index to 0.
|
||||||
|
"""
|
||||||
for i in range(len(self._cards)): #iterates through each card in the deck
|
for i in range(len(self._cards)): #iterates through each card in the deck
|
||||||
j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck
|
j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck
|
||||||
self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck
|
self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck
|
||||||
self._next_card = 0 #Resets the next card index after shuffling.
|
self._next_card = 0 #Resets the next card index after shuffling.
|
||||||
|
|
||||||
def deal(self):
|
def deal(self):
|
||||||
|
"""
|
||||||
|
Deals the next card from the deck. Returns None if there are no cards left to deal.
|
||||||
|
"""
|
||||||
if self._next_card >= len(self._cards):
|
if self._next_card >= len(self._cards):
|
||||||
return None #Returns None if there are no cards left to deal.
|
return None #Returns None if there are no cards left to deal.
|
||||||
card = self._cards[self._next_card]
|
card = self._cards[self._next_card]
|
||||||
@@ -34,6 +48,14 @@ class Deck:
|
|||||||
def number_of_cards(self) -> int:
|
def number_of_cards(self) -> int:
|
||||||
return len(self._cards) - self._next_card #Returns the number of remaining cards in the deck.
|
return len(self._cards) - self._next_card #Returns the number of remaining cards in the deck.
|
||||||
|
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
"""
|
||||||
|
Returns a string representation of the entire deck,
|
||||||
|
with one card per line.
|
||||||
|
"""
|
||||||
|
return "\n".join(str(card) for card in self._cards)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
deck = Deck()
|
deck = Deck()
|
||||||
deck.shuffle() #Calls the shuffle method to randomize the deck.
|
deck.shuffle() #Calls the shuffle method to randomize the deck.
|
||||||
|
|||||||
BIN
Project 1/Project 1.pdf
Normal file
BIN
Project 1/Project 1.pdf
Normal file
Binary file not shown.
@@ -1,19 +1,28 @@
|
|||||||
from Deck import Deck
|
######################################
|
||||||
"""
|
# DCS 229 -- Unfair Solitaire
|
||||||
Defines the Solitaire game logic. Contains methods to play the game by dealing cards, removing cards based on game rules, and checking for a win condition.
|
# Defines the Solitaire game logic. Contains methods to play the game by dealing cards, removing cards based on game rules, and checking for a win condition.
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
|
from Deck import Deck
|
||||||
|
|
||||||
Important Note: The prints in this file only run when this file is ececuted directly. This file should not be executed directly normally.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Solitaire:
|
class Solitaire:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.deck = Deck()
|
self.deck = Deck()
|
||||||
self.face_up = [] #List to hold face-up cards.
|
self.face_up = [] #List to hold face-up cards.
|
||||||
|
|
||||||
|
'''
|
||||||
|
deals cards until there are four face-up cards or the deck is empty.
|
||||||
|
'''
|
||||||
def deal_until_four(self):
|
def deal_until_four(self):
|
||||||
while len(self.face_up) < 4 and self.deck.number_of_cards() > 0:
|
while len(self.face_up) < 4 and self.deck.number_of_cards() > 0:
|
||||||
self.face_up.append(self.deck.deal()) #Deals cards until there are four face-up cards.
|
self.face_up.append(self.deck.deal()) #Deals cards until there are four face-up cards.
|
||||||
|
|
||||||
|
'''
|
||||||
|
removes the last four cards if they are all the same suit. Returns True if cards were removed, False otherwise.
|
||||||
|
'''
|
||||||
def remove_four_same_suit(self) -> bool:
|
def remove_four_same_suit(self) -> bool:
|
||||||
if len(self.face_up) < 4:
|
if len(self.face_up) < 4:
|
||||||
return False #Not enough cards to remove four of the same suit.
|
return False #Not enough cards to remove four of the same suit.
|
||||||
@@ -27,6 +36,9 @@ class Solitaire:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
'''
|
||||||
|
removes the inner two cards if the first and last card of the last four cards are the same suit. Returns True if cards were removed, False otherwise.
|
||||||
|
'''
|
||||||
def remove_inner_two(self) -> bool:
|
def remove_inner_two(self) -> bool:
|
||||||
if len(self.face_up) < 4:
|
if len(self.face_up) < 4:
|
||||||
return False #Not enough cards to remove inner two cards.
|
return False #Not enough cards to remove inner two cards.
|
||||||
@@ -38,6 +50,10 @@ class Solitaire:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Attempts to remove cards based on game rules.
|
||||||
|
'''
|
||||||
def remove_all_possible(self):
|
def remove_all_possible(self):
|
||||||
removed = True
|
removed = True
|
||||||
while removed and len(self.face_up) >= 4:
|
while removed and len(self.face_up) >= 4:
|
||||||
@@ -45,6 +61,9 @@ class Solitaire:
|
|||||||
if not removed:
|
if not removed:
|
||||||
removed = self.remove_inner_two() # Attempts to remove cards based on game rules.
|
removed = self.remove_inner_two() # Attempts to remove cards based on game rules.
|
||||||
|
|
||||||
|
'''
|
||||||
|
plays the game by shuffling the deck, dealing cards, removing cards based on game rules, and checking for a win condition.
|
||||||
|
'''
|
||||||
def playGame(self) -> bool:
|
def playGame(self) -> bool:
|
||||||
self.deck.shuffle()
|
self.deck.shuffle()
|
||||||
self.face_up = []
|
self.face_up = []
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
"""
|
######################################
|
||||||
This is the main file that should be called to run the simulation.
|
# DCS 229 -- Unfair Solitaire
|
||||||
"""
|
# This is the main.py file, which contains the main function to run the simulation.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
from Solitaire import Solitaire
|
from Solitaire import Solitaire
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
Project 1/test.py
Normal file
2
Project 1/test.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
for i in range (0, 10):
|
||||||
|
print(i)
|
||||||
@@ -1,3 +1,11 @@
|
|||||||
|
######################################
|
||||||
|
# DCS 229 -- Project 2
|
||||||
|
# This is the Card.py file, which defines the Card class used in the Solitaire game. The Card class represents a playing card with a suit and value, and includes methods to retrieve the suit and value, as well as a string representation of the card.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
class Card:
|
class Card:
|
||||||
"""
|
"""
|
||||||
Represents a playing card with a suit and value.
|
Represents a playing card with a suit and value.
|
||||||
@@ -23,9 +31,15 @@ class Card:
|
|||||||
|
|
||||||
def __add__(self, other) -> int:
|
def __add__(self, other) -> int:
|
||||||
#Adding 2 cards together
|
#Adding 2 cards together
|
||||||
|
|
||||||
|
return "Cat"
|
||||||
if isinstance(other, Card):
|
if isinstance(other, Card):
|
||||||
return self.value + other.value
|
return self._value + other._value
|
||||||
elif isinstance(other, int):
|
elif isinstance(other, int):
|
||||||
#allows adding a card to an int
|
#allows adding a card to an int
|
||||||
return self.value + other
|
return self._value + other
|
||||||
|
return NotImplemented
|
||||||
|
|
||||||
|
def __radd__(self, other) -> int:
|
||||||
|
return self.__add__(other)
|
||||||
#Added for project 2: Created an "__add__" meathod to allow adding Cards together.
|
#Added for project 2: Created an "__add__" meathod to allow adding Cards together.
|
||||||
|
|||||||
@@ -1,3 +1,11 @@
|
|||||||
|
######################################
|
||||||
|
# DCS 229 -- Project 2
|
||||||
|
# This is the Deck.py file, which defines the Deck class used in the Solitaire game. The Deck class represents a standard 52-card deck, and includes methods to shuffle the deck, deal cards, and check the number of remaining cards.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
import random
|
import random
|
||||||
from Card import Card
|
from Card import Card
|
||||||
"""
|
"""
|
||||||
@@ -18,12 +26,18 @@ class Deck:
|
|||||||
self._cards.append(Card(suit, value)) #creates a standard 52-card deck
|
self._cards.append(Card(suit, value)) #creates a standard 52-card deck
|
||||||
|
|
||||||
def shuffle(self):
|
def shuffle(self):
|
||||||
|
"""
|
||||||
|
Shuffles the deck of cards using the Fisher-Yates algorithm. This algorithm iterates through the deck and swaps each card with a randomly selected card from the remaining unshuffled portion of the deck. After shuffling, it resets the next card index to 0.
|
||||||
|
"""
|
||||||
for i in range(len(self._cards)): #iterates through each card in the deck
|
for i in range(len(self._cards)): #iterates through each card in the deck
|
||||||
j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck
|
j = random.randrange(i, len(self._cards)) #selects a random index from i to the end of the deck
|
||||||
self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck
|
self._cards[i], self._cards[j] = self._cards[j], self._cards[i] #Shuffles the deck
|
||||||
self._next_card = 0 #Resets the next card index after shuffling.
|
self._next_card = 0 #Resets the next card index after shuffling.
|
||||||
|
|
||||||
def deal(self):
|
def deal(self):
|
||||||
|
"""
|
||||||
|
Deals the next card from the deck. Returns None if there are no cards left to deal.
|
||||||
|
"""
|
||||||
if self._next_card >= len(self._cards):
|
if self._next_card >= len(self._cards):
|
||||||
return None #Returns None if there are no cards left to deal.
|
return None #Returns None if there are no cards left to deal.
|
||||||
card = self._cards[self._next_card]
|
card = self._cards[self._next_card]
|
||||||
@@ -33,6 +47,13 @@ class Deck:
|
|||||||
def number_of_cards(self) -> int:
|
def number_of_cards(self) -> int:
|
||||||
return len(self._cards) - self._next_card #Returns the number of remaining cards in the deck.
|
return len(self._cards) - self._next_card #Returns the number of remaining cards in the deck.
|
||||||
|
|
||||||
|
def __repr__(self) -> str:
|
||||||
|
"""
|
||||||
|
Returns a string representation of the entire deck,
|
||||||
|
with one card per line.
|
||||||
|
"""
|
||||||
|
return "\n".join(str(card) for card in self._cards)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
deck = Deck()
|
deck = Deck()
|
||||||
deck.shuffle() #Calls the shuffle method to randomize the deck.
|
deck.shuffle() #Calls the shuffle method to randomize the deck.
|
||||||
|
|||||||
BIN
Project 2/Project 2.pdf
Normal file
BIN
Project 2/Project 2.pdf
Normal file
Binary file not shown.
@@ -1,19 +1,28 @@
|
|||||||
from Deck import Deck
|
######################################
|
||||||
"""
|
# DCS 229 -- Project 2
|
||||||
Defines the Solitaire game logic. Contains methods to play the game by dealing cards, removing cards based on game rules, and checking for a win condition.
|
# Defines the Solitaire game logic. Contains methods to play the game by dealing cards, removing cards based on game rules, and checking for a win condition.
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
|
from Deck import Deck
|
||||||
|
|
||||||
Important Note: The prints in this file only run when this file is ececuted directly. This file should not be executed directly normally.
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Solitaire:
|
class Solitaire:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.deck = Deck()
|
self.deck = Deck()
|
||||||
self.face_up = [] #List to hold face-up cards.
|
self.face_up = [] #List to hold face-up cards.
|
||||||
|
|
||||||
|
'''
|
||||||
|
deals cards until there are four face-up cards or the deck is empty.
|
||||||
|
'''
|
||||||
def deal_until_four(self):
|
def deal_until_four(self):
|
||||||
while len(self.face_up) < 4 and self.deck.number_of_cards() > 0:
|
while len(self.face_up) < 4 and self.deck.number_of_cards() > 0:
|
||||||
self.face_up.append(self.deck.deal()) #Deals cards until there are four face-up cards.
|
self.face_up.append(self.deck.deal()) #Deals cards until there are four face-up cards.
|
||||||
|
|
||||||
|
'''
|
||||||
|
removes the last four cards if they are all the same suit. Returns True if cards were removed, False otherwise.
|
||||||
|
'''
|
||||||
def remove_four_same_suit(self) -> bool:
|
def remove_four_same_suit(self) -> bool:
|
||||||
if len(self.face_up) < 4:
|
if len(self.face_up) < 4:
|
||||||
return False #Not enough cards to remove four of the same suit.
|
return False #Not enough cards to remove four of the same suit.
|
||||||
@@ -27,6 +36,9 @@ class Solitaire:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
'''
|
||||||
|
removes the inner two cards if the first and last card of the last four cards are the same suit. Returns True if cards were removed, False otherwise.
|
||||||
|
'''
|
||||||
def remove_inner_two(self) -> bool:
|
def remove_inner_two(self) -> bool:
|
||||||
if len(self.face_up) < 4:
|
if len(self.face_up) < 4:
|
||||||
return False #Not enough cards to remove inner two cards.
|
return False #Not enough cards to remove inner two cards.
|
||||||
@@ -38,6 +50,9 @@ class Solitaire:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
'''
|
||||||
|
Attempts to remove cards based on game rules.
|
||||||
|
'''
|
||||||
def remove_all_possible(self):
|
def remove_all_possible(self):
|
||||||
removed = True
|
removed = True
|
||||||
while removed and len(self.face_up) >= 4:
|
while removed and len(self.face_up) >= 4:
|
||||||
@@ -45,6 +60,9 @@ class Solitaire:
|
|||||||
if not removed:
|
if not removed:
|
||||||
removed = self.remove_inner_two() # Attempts to remove cards based on game rules.
|
removed = self.remove_inner_two() # Attempts to remove cards based on game rules.
|
||||||
|
|
||||||
|
'''
|
||||||
|
plays the game by shuffling the deck, dealing cards, removing cards based on game rules, and checking for a win condition.
|
||||||
|
'''
|
||||||
def playGame(self) -> bool:
|
def playGame(self) -> bool:
|
||||||
self.deck.shuffle()
|
self.deck.shuffle()
|
||||||
self.face_up = []
|
self.face_up = []
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Project 2/__pycache__/main.cpython-314.pyc
Normal file
BIN
Project 2/__pycache__/main.cpython-314.pyc
Normal file
Binary file not shown.
BIN
Project 2/__pycache__/utilities.cpython-314.pyc
Normal file
BIN
Project 2/__pycache__/utilities.cpython-314.pyc
Normal file
Binary file not shown.
@@ -1,6 +1,11 @@
|
|||||||
"""
|
######################################
|
||||||
This is the main file that should be called to run the simulation.
|
# DCS 229 -- Unfair Solitaire
|
||||||
"""
|
# This is the main.py file, which contains the main function to run the simulation.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
from Solitaire import Solitaire
|
from Solitaire import Solitaire
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,37 @@
|
|||||||
"""
|
######################################
|
||||||
Reo
|
# DCS 229 -- Project 2
|
||||||
"""
|
# This is the utilities.py file, which contains utility functions for the Solitaire game.
|
||||||
|
# Date: 04/01/2026
|
||||||
|
# Name: Benjamin Adovasio
|
||||||
|
# Resources Used: Fran
|
||||||
|
##########################################
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from Card import Card
|
from Card import Card
|
||||||
|
|
||||||
def sum_cards_iter(cards: list[Card]) -> int:
|
'''
|
||||||
|
Added for project 2: Created a function to sum a list of Card objects using iteration.
|
||||||
|
'''
|
||||||
|
def sum_cards_iter(cards: list[Card]) -> int: #start total at 0
|
||||||
total = 0 #start total at 0
|
total = 0 #start total at 0
|
||||||
for card in cards:
|
for card in cards:
|
||||||
total = total + card
|
total = total + card #Adds the value of each card to the total using iteration.
|
||||||
return total
|
return total
|
||||||
#Added for project 2: Created a function to sum a list of Card objects using iteration.
|
|
||||||
|
|
||||||
def sum_cards_recursive(cards: list[Card]) -> int:
|
'''
|
||||||
|
Added for project 2: Created a function to sum a list of Card objects using recursion.
|
||||||
|
'''
|
||||||
|
def sum_cards_recursive(cards: list[Card]) -> int: #start total at 0
|
||||||
if cards == []:
|
if cards == []:
|
||||||
#Base case
|
#Base case
|
||||||
return 0
|
return 0 #If the list of cards is empty, return 0.
|
||||||
return cards[0] + sum_cards_recursive(cards[1:])
|
return cards[0] + sum_cards_recursive(cards[1:]) #Adds the value of the first card to the sum of the remaining cards using recursion.
|
||||||
#Recursive case
|
#Recursive case
|
||||||
#Added for project 2: Created a function to sum a list of Card objects using recursion.
|
|
||||||
|
|
||||||
|
|
||||||
|
'''
|
||||||
|
Added for project 2: Example tests given
|
||||||
|
'''
|
||||||
def test_sum_cards():
|
def test_sum_cards():
|
||||||
cards = [
|
cards = [
|
||||||
Card("diamond", 5),
|
Card("diamond", 5),
|
||||||
@@ -26,6 +39,8 @@ def test_sum_cards():
|
|||||||
Card("spade", 12),
|
Card("spade", 12),
|
||||||
Card("clubs", 1)
|
Card("clubs", 1)
|
||||||
]
|
]
|
||||||
assert sum_cards_iter(cards) == 21
|
print(sum_cards_iter(cards))
|
||||||
assert sum_cards_recursive(cards) == 21
|
# assert sum_cards_iter(cards) == 21
|
||||||
#Added for project 2: Example tests given
|
# assert sum_cards_recursive(cards) == 21
|
||||||
|
|
||||||
|
test_sum_cards()
|
||||||
BIN
Project 3/OLD V2 Project 3.pdf
Normal file
BIN
Project 3/OLD V2 Project 3.pdf
Normal file
Binary file not shown.
BIN
Project 3/__pycache__/project_3_search.cpython-314.pyc
Normal file
BIN
Project 3/__pycache__/project_3_search.cpython-314.pyc
Normal file
Binary file not shown.
@@ -9,15 +9,18 @@
|
|||||||
|
|
||||||
import random #to generate the 100 random values
|
import random #to generate the 100 random values
|
||||||
import time #for part 4, to calculae total time
|
import time #for part 4, to calculae total time
|
||||||
|
from collections.abc import Sequence
|
||||||
|
|
||||||
#I decided to put all 4 functions into one class to keep it organized
|
#I decided to put all 4 functions into one class to keep it organized
|
||||||
class Search:
|
class Search:
|
||||||
|
|
||||||
|
def generate_random_list(self, n: int) -> list[int]:
|
||||||
"""
|
"""
|
||||||
This function generates the list of random integers.
|
This function generates a list of n random integers between 0 and 1000, and returns the list.
|
||||||
|
Args: n: the number of random integers to generate
|
||||||
|
Returns: a list of n random integers between 0 and 1000
|
||||||
"""
|
"""
|
||||||
def generate_random_list(self, n):
|
array: list[int] = [] #array starts as blank
|
||||||
array = [] #array starts as blank
|
|
||||||
for element in range(n): #will run n times
|
for element in range(n): #will run n times
|
||||||
array.append(random.randint(0, 1000)) #random integer between 0-1000
|
array.append(random.randint(0, 1000)) #random integer between 0-1000
|
||||||
|
|
||||||
@@ -27,10 +30,12 @@ class Search:
|
|||||||
|
|
||||||
return array
|
return array
|
||||||
|
|
||||||
|
def linear_search_print(self, arr: Sequence[int], target: int) -> int:
|
||||||
"""
|
"""
|
||||||
This funciton preforms a search on the list for the target value, and prints the number of checks it took to find the target.
|
This function performs a linear search for the target value in the given array. It prints the number of unsuccessful checks it took to find the target value, and returns the number of checks. If the target value is not found, it prints "Not found." and returns the total number of checks.
|
||||||
|
Args: arr: the array to search through, target: the value to search for
|
||||||
|
Returns: the number of checks it took to find the target value, or the total number of checks if the target value is not found
|
||||||
"""
|
"""
|
||||||
def linear_search_print(self, arr, target):
|
|
||||||
checks = 0 #check count starts at 0
|
checks = 0 #check count starts at 0
|
||||||
for value in arr:
|
for value in arr:
|
||||||
if value == target:
|
if value == target:
|
||||||
@@ -41,10 +46,13 @@ class Search:
|
|||||||
print("Not found.") #Only gets printed if the code doesnt return earlier
|
print("Not found.") #Only gets printed if the code doesnt return earlier
|
||||||
return checks
|
return checks
|
||||||
|
|
||||||
|
|
||||||
|
def linear_search_count(self, arr: Sequence[int], target: int) -> int:
|
||||||
"""
|
"""
|
||||||
This function is the same as the previous one, but instead of printing the number of checks, it returns the number of checks.
|
This function performs a linear search for the target value in the given array. It returns the number of checks it took to find the target value, or the total number of checks if the target value is not found.
|
||||||
|
Args: arr: the array to search through, target: the value to search for
|
||||||
|
Returns: the number of checks it took to find the target value, or the total number of checks if the target value is not found
|
||||||
"""
|
"""
|
||||||
def linear_search_count(self, arr, target):
|
|
||||||
checks = 0
|
checks = 0
|
||||||
for value in arr:
|
for value in arr:
|
||||||
checks += 1
|
checks += 1
|
||||||
@@ -52,10 +60,22 @@ class Search:
|
|||||||
return checks
|
return checks
|
||||||
return checks
|
return checks
|
||||||
|
|
||||||
|
|
||||||
|
def binary_search_recursive(
|
||||||
|
self,
|
||||||
|
arr: Sequence[int],
|
||||||
|
target: int,
|
||||||
|
low: int = 0,
|
||||||
|
high: int | None = None,
|
||||||
|
) -> int:
|
||||||
"""
|
"""
|
||||||
This function uses recursive searching.
|
This function performs a binary search for the target value in the given sorted array. It returns the index of the target value if found, or -1 if not found.
|
||||||
|
Args: arr: the sorted array to search through, target: the value to search for
|
||||||
|
Returns: the index of the target value if found, or -1 if not found
|
||||||
"""
|
"""
|
||||||
def binary_search_recursive(self, arr, target, low, high):
|
if high is None:
|
||||||
|
high = len(arr) - 1
|
||||||
|
|
||||||
if low > high:
|
if low > high:
|
||||||
return -1 #base case: if low is greater than high, the target is not found
|
return -1 #base case: if low is greater than high, the target is not found
|
||||||
|
|
||||||
@@ -68,7 +88,12 @@ class Search:
|
|||||||
else:
|
else:
|
||||||
return self.binary_search_recursive(arr, target, low, mid - 1)
|
return self.binary_search_recursive(arr, target, low, mid - 1)
|
||||||
|
|
||||||
def main():
|
def main(n: int = 1000) -> None:
|
||||||
|
"""
|
||||||
|
This function is the main function that runs the search tests. It generates random lists of integers, performs linear and binary searches, and prints the results.
|
||||||
|
Args: n: the number of random integers to generate for the tests (default is 1000)
|
||||||
|
Returns: None
|
||||||
|
"""
|
||||||
search = Search() #search object to call Search() class
|
search = Search() #search object to call Search() class
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -92,16 +117,13 @@ def main():
|
|||||||
Part 3: Uses the recursive search
|
Part 3: Uses the recursive search
|
||||||
"""
|
"""
|
||||||
arr = sorted(search.generate_random_list(100)) #generate the list of 100 random integers and sort it for binary search
|
arr = sorted(search.generate_random_list(100)) #generate the list of 100 random integers and sort it for binary search
|
||||||
index = search.binary_search_recursive(arr, 42, 0, len(arr) - 1) #search for the value 42 using binary search and get the index of 42
|
index = search.binary_search_recursive(arr, 42) #search for the value 42 using binary search and get the index of 42
|
||||||
print("Index of 42 in sorted array:", index) #print the index of 42 in the sorted array
|
print("Index of 42 in sorted array:", index) #print the index of 42 in the sorted array
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Part 4: Tests
|
Part 4: Tests
|
||||||
|
|
||||||
At what number of queries does Sorting + Binary Search start to show an advantage over Linear Search?:
|
|
||||||
Sorting + binary search shows an advantage at around 500 queries
|
|
||||||
"""
|
"""
|
||||||
n = 1000
|
|
||||||
arr = search.generate_random_list(n) #generate the list of n random integers
|
arr = search.generate_random_list(n) #generate the list of n random integers
|
||||||
|
|
||||||
for multiplier in [0.5, 1, 2, 4]: #I used a "multiplier" to avoid rewriting the code for each query
|
for multiplier in [0.5, 1, 2, 4]: #I used a "multiplier" to avoid rewriting the code for each query
|
||||||
@@ -112,17 +134,17 @@ def main():
|
|||||||
queries.append(random.choice(arr))
|
queries.append(random.choice(arr))
|
||||||
|
|
||||||
# Linear timing
|
# Linear timing
|
||||||
start = time.perf_counter()
|
start = time.perf_counter() #start time is recorded before any of the queries are searched for using linear search
|
||||||
for q in queries:
|
for q in queries:
|
||||||
search.linear_search_count(arr, q)
|
search.linear_search_count(arr, q) #search for each query using linear search on the unsorted array
|
||||||
end = time.perf_counter()
|
end = time.perf_counter() #end time is recorded after all queries have been searched for using linear search
|
||||||
linear_time = end - start
|
linear_time = end - start
|
||||||
|
|
||||||
# Sorting + Binary timing
|
# Sorting + Binary timing
|
||||||
start = time.perf_counter()
|
start = time.perf_counter() #start time is recorded before the array is sorted and any of the queries are searched for using binary search
|
||||||
sorted_arr = sorted(arr)
|
sorted_arr = sorted(arr) #the array is sorted before the queries are searched for using binary search, but the time it takes to sort the array is included in the total time for this part
|
||||||
for q in queries:
|
for q in queries:
|
||||||
search.binary_search_recursive(sorted_arr, q, 0, len(sorted_arr) - 1)
|
search.binary_search_recursive(sorted_arr, q) #search for each query using binary search on the sorted array
|
||||||
end = time.perf_counter()
|
end = time.perf_counter()
|
||||||
binary_time = end - start
|
binary_time = end - start
|
||||||
|
|
||||||
|
|||||||
@@ -1,205 +1,90 @@
|
|||||||
######################################
|
######################################
|
||||||
# DCS 229 -- TurtleDFS
|
# DCS 229 -- TurtleDFS
|
||||||
# Non-recursive depth first search for solving turtle mazes
|
# Depth-First Search implementation for Turtle Maze
|
||||||
# Date: 03/29/2026
|
# Date: 03/29/2026
|
||||||
# Name: Benjamin Adovasio
|
# Name: Benjamin Adovasio
|
||||||
# Resources Used: Project 5 handout and TurtleMaze.py
|
# Resources Used: I worked with Pat Cohen on the project.
|
||||||
##########################################
|
##########################################
|
||||||
|
|
||||||
from __future__ import annotations
|
import os
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
import sys
|
|
||||||
from types import SimpleNamespace
|
|
||||||
|
|
||||||
from Stack import Stack
|
from Stack import Stack
|
||||||
|
from TurtleMaze import TurtleMaze, Cell, Contents
|
||||||
try:
|
|
||||||
import turtle
|
|
||||||
TURTLE_AVAILABLE = True
|
|
||||||
except ModuleNotFoundError:
|
|
||||||
TURTLE_AVAILABLE = False
|
|
||||||
|
|
||||||
class _StubTerminator(Exception):
|
|
||||||
"""Fallback replacement for turtle.Terminator."""
|
|
||||||
|
|
||||||
class _StubScreen:
|
|
||||||
def setworldcoordinates(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tracer(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def update(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def mainloop(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
class _StubTurtle:
|
|
||||||
def __init__(self):
|
|
||||||
self.screen = _StubScreen()
|
|
||||||
|
|
||||||
def shape(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def speed(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def up(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def goto(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def color(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def fillcolor(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def setheading(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def down(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def begin_fill(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def forward(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def right(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def end_fill(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def dot(self, *args) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def towards(self, *args) -> int:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
turtle = SimpleNamespace(
|
|
||||||
Turtle=_StubTurtle,
|
|
||||||
Screen=_StubScreen,
|
|
||||||
Terminator=_StubTerminator,
|
|
||||||
)
|
|
||||||
sys.modules["turtle"] = turtle
|
|
||||||
|
|
||||||
from TurtleMaze import Cell, Contents, TurtleMaze
|
|
||||||
|
|
||||||
|
|
||||||
class TestMaze:
|
|
||||||
"""Lightweight maze implementation used for non-GUI testing."""
|
|
||||||
|
|
||||||
def __init__(self, maze_file_name: str | Path):
|
|
||||||
self.maze_grid: list[list[Cell]] = []
|
|
||||||
self._path_log: list[tuple[int, int, Contents | None]] = []
|
|
||||||
|
|
||||||
maze_path = Path(maze_file_name)
|
|
||||||
for row_index, line in enumerate(maze_path.read_text().splitlines()):
|
|
||||||
row_list: list[Cell] = []
|
|
||||||
for col_index, char in enumerate(line):
|
|
||||||
cell = Cell(row_index, col_index, Contents(char))
|
|
||||||
row_list.append(cell)
|
|
||||||
|
|
||||||
if cell._contents == Contents.START:
|
|
||||||
self._start = cell
|
|
||||||
if cell._contents == Contents.GOAL:
|
|
||||||
self._goal = cell
|
|
||||||
|
|
||||||
self.maze_grid.append(row_list)
|
|
||||||
|
|
||||||
def updatePosition(self, cell: Cell, val: Contents | None = None) -> None:
|
|
||||||
"""Track visited positions during tests without opening a turtle window."""
|
|
||||||
if val is not None:
|
|
||||||
cell._contents = val
|
|
||||||
self._path_log.append((cell.x, cell.y, val))
|
|
||||||
|
|
||||||
def getStart(self) -> Cell:
|
|
||||||
return self._start
|
|
||||||
|
|
||||||
def getGoal(self) -> Cell:
|
|
||||||
return self._goal
|
|
||||||
|
|
||||||
def __getitem__(self, idx: int) -> list[Cell]:
|
|
||||||
return self.maze_grid[idx]
|
|
||||||
|
|
||||||
|
|
||||||
def get_neighbors(maze: TurtleMaze, cell: Cell) -> list[Cell]:
|
def get_neighbors(maze: TurtleMaze, cell: Cell) -> list[Cell]:
|
||||||
"""Return each non-obstacle neighbor in north, south, east, west order."""
|
'''returns a list of non-obstacle neighbors in north, south, east, west order'''
|
||||||
neighbors: list[Cell] = []
|
|
||||||
candidate_positions = (
|
|
||||||
(cell.y - 1, cell.x), # north
|
|
||||||
(cell.y + 1, cell.x), # south
|
|
||||||
(cell.y, cell.x + 1), # east
|
|
||||||
(cell.y, cell.x - 1), # west
|
|
||||||
)
|
|
||||||
|
|
||||||
for row, col in candidate_positions:
|
neighbors = []
|
||||||
if 0 <= row < len(maze.maze_grid) and 0 <= col < len(maze[row]):
|
row = cell.y
|
||||||
neighbor = maze[row][col]
|
col = cell.x
|
||||||
if not neighbor.isBlocked():
|
|
||||||
neighbors.append(neighbor)
|
# north
|
||||||
|
if row - 1 >= 0:
|
||||||
|
north = maze[row - 1][col]
|
||||||
|
if not north.isBlocked():
|
||||||
|
neighbors.append(north)
|
||||||
|
|
||||||
|
# south
|
||||||
|
if row + 1 < len(maze.maze_grid):
|
||||||
|
south = maze[row + 1][col]
|
||||||
|
if not south.isBlocked():
|
||||||
|
neighbors.append(south)
|
||||||
|
|
||||||
|
# east
|
||||||
|
if col + 1 < len(maze[0]):
|
||||||
|
east = maze[row][col + 1]
|
||||||
|
if not east.isBlocked():
|
||||||
|
neighbors.append(east)
|
||||||
|
|
||||||
|
# west
|
||||||
|
if col - 1 >= 0:
|
||||||
|
west = maze[row][col - 1]
|
||||||
|
if not west.isBlocked():
|
||||||
|
neighbors.append(west)
|
||||||
|
|
||||||
return neighbors
|
return neighbors
|
||||||
|
|
||||||
|
|
||||||
def _mark_solution_path(maze: TurtleMaze, goal: Cell) -> None:
|
|
||||||
"""Walk the successful route without teleporting and color it green."""
|
|
||||||
goal_to_start: list[Cell] = []
|
|
||||||
current: Cell | None = goal
|
|
||||||
|
|
||||||
while current is not None:
|
|
||||||
goal_to_start.append(current)
|
|
||||||
current = current.getParent()
|
|
||||||
|
|
||||||
for cell in goal_to_start:
|
|
||||||
maze.updatePosition(cell, Contents.PART_OF_PATH)
|
|
||||||
|
|
||||||
for cell in reversed(goal_to_start[:-1]):
|
|
||||||
maze.updatePosition(cell, Contents.PART_OF_PATH)
|
|
||||||
|
|
||||||
|
|
||||||
def dfs(maze: TurtleMaze) -> bool:
|
def dfs(maze: TurtleMaze) -> bool:
|
||||||
"""Solve a maze using a non-recursive depth first search."""
|
'''runs a non-recursive depth first search on the maze with backtracking
|
||||||
|
Returns:
|
||||||
|
True if the goal is found, False otherwise
|
||||||
|
'''
|
||||||
|
|
||||||
|
stack = Stack()
|
||||||
start = maze.getStart()
|
start = maze.getStart()
|
||||||
stack: Stack[Cell] = Stack()
|
visited = set()
|
||||||
visited: set[tuple[int, int]] = set()
|
|
||||||
|
|
||||||
stack.push(start)
|
stack.push(start)
|
||||||
visited.add((start.x, start.y))
|
visited.add((start.y, start.x))
|
||||||
maze.updatePosition(start, Contents.TRIED)
|
maze.updatePosition(start)
|
||||||
|
|
||||||
while not stack.is_empty():
|
while not stack.is_empty():
|
||||||
current = stack.peek()
|
current = stack.peek()
|
||||||
|
|
||||||
|
# if we reached the goal, we are done
|
||||||
if current.isGoal():
|
if current.isGoal():
|
||||||
_mark_solution_path(maze, current)
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
next_cell = None
|
found_next = False
|
||||||
|
|
||||||
|
# look for an unvisited neighbor
|
||||||
for neighbor in get_neighbors(maze, current):
|
for neighbor in get_neighbors(maze, current):
|
||||||
coordinates = (neighbor.x, neighbor.y)
|
if (neighbor.y, neighbor.x) not in visited:
|
||||||
if coordinates not in visited:
|
|
||||||
neighbor.setParent(current)
|
neighbor.setParent(current)
|
||||||
next_cell = neighbor
|
visited.add((neighbor.y, neighbor.x))
|
||||||
|
stack.push(neighbor)
|
||||||
|
|
||||||
|
if not neighbor.isGoal():
|
||||||
|
maze.updatePosition(neighbor, Contents.TRIED)
|
||||||
|
else:
|
||||||
|
maze.updatePosition(neighbor)
|
||||||
|
|
||||||
|
found_next = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if next_cell is not None:
|
# if no unvisited neighbor exists, backtrack
|
||||||
visited.add((next_cell.x, next_cell.y))
|
if not found_next:
|
||||||
stack.push(next_cell)
|
|
||||||
|
|
||||||
if next_cell.isGoal():
|
|
||||||
maze.updatePosition(next_cell)
|
|
||||||
else:
|
|
||||||
maze.updatePosition(next_cell, Contents.TRIED)
|
|
||||||
continue
|
|
||||||
|
|
||||||
dead_end = stack.pop()
|
dead_end = stack.pop()
|
||||||
|
|
||||||
if dead_end != start and not dead_end.isGoal():
|
if dead_end != start and not dead_end.isGoal():
|
||||||
maze.updatePosition(dead_end, Contents.DEAD_END)
|
maze.updatePosition(dead_end, Contents.DEAD_END)
|
||||||
|
|
||||||
@@ -208,48 +93,14 @@ def dfs(maze: TurtleMaze) -> bool:
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
def _project_path(file_name: str) -> Path:
|
maze = TurtleMaze('maze_1.txt')
|
||||||
"""Return a path inside the Project 5 directory."""
|
|
||||||
return Path(__file__).resolve().with_name(file_name)
|
|
||||||
|
|
||||||
|
|
||||||
def _test_get_neighbors() -> None:
|
|
||||||
maze = TestMaze(_project_path("maze_1.txt"))
|
|
||||||
start = maze.getStart()
|
|
||||||
neighbor_coordinates = [(cell.x, cell.y) for cell in get_neighbors(maze, start)]
|
|
||||||
|
|
||||||
assert neighbor_coordinates == [(5, 1), (3, 1)]
|
|
||||||
|
|
||||||
|
|
||||||
def _test_dfs() -> None:
|
|
||||||
for maze_name in ("maze_1.txt", "maze_2.txt", "maze_3.txt"):
|
|
||||||
maze = TestMaze(_project_path(maze_name))
|
|
||||||
solved = dfs(maze)
|
|
||||||
|
|
||||||
assert solved is True
|
|
||||||
assert maze.getStart()._contents == Contents.PART_OF_PATH
|
|
||||||
assert maze.getGoal()._contents == Contents.PART_OF_PATH
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
_test_get_neighbors()
|
|
||||||
_test_dfs()
|
|
||||||
print("All TurtleDFS tests passed.")
|
|
||||||
|
|
||||||
if not TURTLE_AVAILABLE:
|
|
||||||
print("Skipping turtle visualization: turtle graphics are unavailable in this Python environment.")
|
|
||||||
return
|
|
||||||
|
|
||||||
maze_path = _project_path("maze_2.txt")
|
|
||||||
try:
|
|
||||||
maze = TurtleMaze(str(maze_path))
|
|
||||||
maze.drawMaze()
|
maze.drawMaze()
|
||||||
|
|
||||||
solved = dfs(maze)
|
solved = dfs(maze)
|
||||||
print(f"Visual DFS demo on {maze_path.name}: {solved}")
|
print("Maze solved:", solved)
|
||||||
|
|
||||||
maze.t.screen.mainloop()
|
maze.t.screen.mainloop()
|
||||||
except Exception as err:
|
|
||||||
print(f"Skipping turtle visualization: {err}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -235,16 +235,27 @@ class TurtleMaze:
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
maze = TurtleMaze('maze_3.txt')
|
maze = TurtleMaze('maze_2.txt')
|
||||||
maze.drawMaze()
|
maze.drawMaze()
|
||||||
# print("row at index 4", maze[4])
|
|
||||||
# print("cell at index 4, 4", maze[4][4])
|
|
||||||
|
|
||||||
|
# print the contents of the top-right corner
|
||||||
|
top_right = maze[0][len(maze[0]) - 1]
|
||||||
|
print("Top-right corner:", top_right)
|
||||||
|
|
||||||
|
# print the start and goal cells
|
||||||
|
print("Start cell:", maze.getStart())
|
||||||
|
print("Goal cell:", maze.getGoal())
|
||||||
|
|
||||||
|
# start at S
|
||||||
maze.updatePosition(maze.getStart())
|
maze.updatePosition(maze.getStart())
|
||||||
print(maze.getStart())
|
|
||||||
|
# move only to neighboring cells so the turtle stays on the path
|
||||||
|
maze.updatePosition(maze[9][15], Contents.TRIED) # down 1
|
||||||
|
maze.updatePosition(maze[9][16], Contents.PART_OF_PATH) # right 1
|
||||||
|
maze.updatePosition(maze[9][17], Contents.PART_OF_PATH) # right 1
|
||||||
|
maze.updatePosition(maze[8][17], Contents.DEAD_END) # up 1
|
||||||
|
|
||||||
maze.t.screen.mainloop()
|
maze.t.screen.mainloop()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user