Skip to content
Open
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
187 changes: 187 additions & 0 deletions GroupFolder/TicTacToe
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
# Tic Tac Toe

import random

def drawBoard(board):
# This function prints out the board that it was passed.

# "board" is a list of 10 strings representing the board (ignore index 0)
print(' | |')
print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6])
print(' | |')
print('-----------')
print(' | |')
print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3])
print(' | |')

def inputPlayerLetter():
# Lets the player type which letter they want to be.
# Returns a list with the player's letter as the first item, and the computer's letter as the second.
letter = ''
while not (letter == 'X' or letter == 'O'):
print('Do you want to be X or O?')
letter = input().upper()

# the first element in the tuple is the player's letter, the second is the computer's letter.
if letter == 'X':
return ['X', 'O']
else:
return ['O', 'X']

def whoGoesFirst():
# Randomly choose the player who goes first.
if random.randint(0, 1) == 0:
return 'computer'
else:
return 'player'

def playAgain():
# This function returns True if the player wants to play again, otherwise it returns False.
print('Do you want to play again? (yes or no)')
return input().lower().startswith('y')

def makeMove(board, letter, move):
board[move] = letter

def isWinner(bo, le):
# Given a board and a player's letter, this function returns True if that player has won.
# We use bo instead of board and le instead of letter so we don't have to type as much.
return ((bo[7] == le and bo[8] == le and bo[9] == le) or # across the top
(bo[4] == le and bo[5] == le and bo[6] == le) or # across the middle
(bo[1] == le and bo[2] == le and bo[3] == le) or # across the bottom
(bo[7] == le and bo[4] == le and bo[1] == le) or # down the left side
(bo[8] == le and bo[5] == le and bo[2] == le) or # down the middle
(bo[9] == le and bo[6] == le and bo[3] == le) or # down the right side
(bo[7] == le and bo[5] == le and bo[3] == le) or # diagonal
(bo[9] == le and bo[5] == le and bo[1] == le)) # diagonal

def getBoardCopy(board):
# Make a duplicate of the board list and return it the duplicate.
dupeBoard = []

for i in board:
dupeBoard.append(i)

return dupeBoard

def isSpaceFree(board, move):
# Return true if the passed move is free on the passed board.
return board[move] == ' '

def getPlayerMove(board):
# Let the player type in his move.
move = ' '
while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):
print('What is your next move? (1-9)')
move = input()
return int(move)

def chooseRandomMoveFromList(board, movesList):
# Returns a valid move from the passed list on the passed board.
# Returns None if there is no valid move.
possibleMoves = []
for i in movesList:
if isSpaceFree(board, i):
possibleMoves.append(i)

if len(possibleMoves) != 0:
return random.choice(possibleMoves)
else:
return None

def getComputerMove(board, computerLetter):
# Given a board and the computer's letter, determine where to move and return that move.
if computerLetter == 'X':
playerLetter = 'O'
else:
playerLetter = 'X'

# Here is our algorithm for our Tic Tac Toe AI:
# First, check if we can win in the next move
for i in range(1, 10):
copy = getBoardCopy(board)
if isSpaceFree(copy, i):
makeMove(copy, computerLetter, i)
if isWinner(copy, computerLetter):
return i

# Check if the player could win on his next move, and block them.
for i in range(1, 10):
copy = getBoardCopy(board)
if isSpaceFree(copy, i):
makeMove(copy, playerLetter, i)
if isWinner(copy, playerLetter):
return i

# Try to take one of the corners, if they are free.
move = chooseRandomMoveFromList(board, [1, 3, 7, 9])
if move != None:
return move

# Try to take the center, if it is free.
if isSpaceFree(board, 5):
return 5

# Move on one of the sides.
return chooseRandomMoveFromList(board, [2, 4, 6, 8])

def isBoardFull(board):
# Return True if every space on the board has been taken. Otherwise return False.
for i in range(1, 10):
if isSpaceFree(board, i):
return False
return True


print('Welcome to Tic Tac Toe!')

while True:
# Reset the board
theBoard = [' '] * 10
playerLetter, computerLetter = inputPlayerLetter()
turn = whoGoesFirst()
print('The ' + turn + ' will go first.')
gameIsPlaying = True

while gameIsPlaying:
if turn == 'player':
# Player's turn.
drawBoard(theBoard)
move = getPlayerMove(theBoard)
makeMove(theBoard, playerLetter, move)

if isWinner(theBoard, playerLetter):
drawBoard(theBoard)
print('Hooray! You have won the game!')
gameIsPlaying = False
else:
if isBoardFull(theBoard):
drawBoard(theBoard)
print('The game is a tie!')
break
else:
turn = 'computer'

else:
# Computer's turn.
move = getComputerMove(theBoard, computerLetter)
makeMove(theBoard, computerLetter, move)

if isWinner(theBoard, computerLetter):
drawBoard(theBoard)
print('The computer has beaten you! You lose.')
gameIsPlaying = False
else:
if isBoardFull(theBoard):
drawBoard(theBoard)
print('The game is a tie!')
break
else:
turn = 'player'

if not playAgain():
break
5 changes: 5 additions & 0 deletions MemberInfo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Name,Best Contact,Discord Username(# included)

Joseph Tuazon, (310) 756 - 8447, CuddlyLicky(#0435)
Jarod Nakamoto, Discord, poiuytrewq7(#9820)
kelsey coen, (510)8813831,potatosalad82(#1200)
14 changes: 14 additions & 0 deletions Nakamoto-Jarod/A1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def FizzBuzz(N=0, M=100):
for i in range(N,M):
out = ""
if i%3==0:
out+="Fizz"
if i%5==0:
out+="Buzz"
if out != "":
print(out)
else:
print(i)

FizzBuzz()
FizzBuzz(10,15)
57 changes: 57 additions & 0 deletions Nakamoto-Jarod/A4b - Radix Sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 11 20:07:04 2018

@author: Jarod
"""

#load in text file
inflobj = open('BookText.txt.txt','r')
lines = inflobj.readlines()
text = []
for i in range(0, len(lines)):
text.extend(lines[i].split())
print(text)

#create buckets
numCharacters = 60
buckets = [[] for i in range(0, numCharacters)]

#find longest element
max_length = len(text[0])
for i in range(1, len(text)):
temp = len(text[i])
if temp > max_length:
max_length = temp

print("Maximum length: " + str(max_length))

#make everything the same length
for i in range(0, len(text)):
#print(text[i])
text[i] = '{:>{}s}'.format(text[i], max_length)
#print(text[i])

print(text)

print()

i = 0
while i < max_length:
#fill buckets
for m in range(0,len(text)):
j = m + 97
if(i == 0):
buckets[int(ord(text[j][-1*(i+1):])-65)].append(text[j])
else:
buckets[int(ord(text[j][-1*(i+1):-1*i])-65)].append(text[j])
text.clear()
#empty buckets
for m in range(0, numCharacters):
j = m + 97
for k in range(0, len(buckets[j])):
text.append(buckets[j].pop(0))

i = i+1

print(text)
69 changes: 69 additions & 0 deletions Nakamoto-Jarod/BookText.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
at his house�s outer gates and take his stand,
armed with his helmet, shield and pair of spears,
as strong as the man I glimpsed that first time
in our own house, drinking wine and reveling there �
just come in from Ephyra, visiting Ilus, Mermerus� son.
Odysseus sailed that way, you see, in his swift trim ship,
hunting deadly poison to smear on his arrows� bronze heads.
Ilus refused�he feared the wrath of the everlasting gods�
but father, so fond of him, gave him all he wanted.
If only that Odysseus sported with these suitors,
a blood wedding, a quick death would take the lot!
True, but all lies in the lap of the great gods,
whether or not he�ll come and pay them back,
here, in his own house.
But you, I urge you,think how to drive these suitors from your halls.
Come now, listen closely. Take my words to heart.
At daybreak summon the island�s lords to full assembly,
give your orders to all and call the gods to witness:
tell the suitors to scatter, each to his own place.
As for your mother, if the spirit moves her to marry,
let her go back to her father�s house, a man of power.
Her kin will arrange the wedding, provide the gifts,
the array that goes with a daughter dearly loved.
For you,I have some good advice, if only you will accept it.
Fit out a ship with twenty oars, the best in sight,
sail in quest of news of your long-lost father.
Someone may tell you something
or you may catch a rumor straight from Zeus,
rumor that carries news to men like nothing else.
First go down to Pylos, question old King Nestor,
then cross over to Sparta, to red-haired Menelaus,
of all the bronze-armored Achaeans the last man back.
Now, if you hear your father�s alive and heading home,
hard-pressed as you are, brave out one more year.
If you hear he�s dead, no longer among the living,
then back you come to the native land you love.
raise his grave-mound, build his honors high
with the full funeral rites that he deserves�
and give your mother to another husband.
Then,once you�ve sealed those matters, seen them through,
think hard, reach down deep in your heart and soul
for a way to kill these suitors in your house,
by stealth or in open combat.
You must not cling to your boyhood any longer�
it�s time you were a man. Haven�t you heard
what glory Prince Orestes won throughout the world
when he killed that cunning, murderous Aegisthus,
who�d killed his famous father?
And you, my friend�how tall and handsome I see you now�be brave, you too,
so men to come will sing your praises down the years.
But now I must go back to my swift trim ship
and all my shipmates, chafing there, I�m sure,
waiting for my return. It all rests with you.
Take my words to heart.�
�Oh stranger,�heedful Telemachus replied, �indeed I will.
You�ve counseled me with so much kindness now,
like a father to a son. I won�t forget a word.
But come, stay longer, keen as you are to sail,
so you can bathe and rest and lift your spirits,
then go back to your ship, delighted with a gift,
a prize of honor, something rare and fine
as a keepsake from myself. The kind of gift
a host will give a stranger, friend to friend.�
Her eyes glinting, Pallas declined in haste:
�Not now. Don�t hold me here. I long to be on my way.
As for the gift�whatever you�d give in kindness�
save it for my return so I can take it home.
Choose something rare and fine, and a good reward
that gift is going to bring you.�
46 changes: 46 additions & 0 deletions Nakamoto-Jarod/Project3Info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
In an attempt to start communication between group members I present project 3:
Ideally all data in this project would really be data from your group members. I encourage
you guys to get the neccessary info to complete this project.
If you are unable to get the info...or don't want to give your real info, make it up.

In project3 you will

Write 3 Classes:
Group_# (Your group number there)
GroupMember
Class

Group_#()
has an list filled with GroupMembers*
*this list must contain at least 2 groupMembers

will have the following functions:
1) meet_up(day,time)
- takes a day(string..Example "Monday") and time(double...example 12.50 for 12:50pm / 15.0 for 3pm / 3.3 for 3:30am)*
*if you would like to format your time another way go for it...just make a note of it in your code
- this method will check the GroupMembers Class schedule if the members will be able to meet durring that time.
- print the result

2) print_members()
-prints all members names, major and schedule



GroupMember()
constructor needed parameters: name, major, classSchdule[]
*classSchedule is a list filled with Class objects

has following functions:
1)print_schedule
prints the members classSchedule


Class()
constructor with
- String department
- ints classNumber, startTime and endTime
- list meetingDays with Days class occurs

functions:
1) print_class_info()
- returns a string with the values from above /\
5 changes: 5 additions & 0 deletions Nakamoto-Jarod/Project4b.txt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Use Radix sort to sort the text from BookText.txt into alphabetical order.
Radix sort was featured in Thursday's lecture and is available on
Google Colab. You may use that code or make your own.

*Note: You will need 26 buckets.
Loading