Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mykeys.py
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: python
python:
- "3.6"
- "3.7"
# command to install dependencies
install:
- pip install -r requirements.txt
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ Evaluation will consist in continuous control and a mid term test.
Evaluation will take into account your code quality and assignements coverage but also github pull request and commits naming conventions and code comments...

Prefer better quality code, ready to be shared and enhanced by others, instead of too rapidly written code, unreadable, un-commented that people will throw to trash and completely rewrite !

modification test :D

[![Coverage Status](https://coveralls.io/repos/github/Antoine01100/BachelorDIM-Lectures-Algorithms-2020/badge.svg?branch=master)](https://coveralls.io/github/Antoine01100/BachelorDIM-Lectures-Algorithms-2020?branch=master)
199 changes: 199 additions & 0 deletions assignements/S1_algotools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 15 14:14:06 2020
@author: bouvaran
"""
import numpy as np
import random

#////////////////////////////////////////////
"""
Q1 :If "som" isn't initialized, I have an error because the
variable have to be referenced before assignement
Q2 :I have an error, I can't split by 0
"ZeroDivisionError: division by zero"
"""
def average_above_zero(theTab:int):
"""
This function calculates the average of the table

Parameters :
som: Contains the sum of the numbers in theTab
n: contains the number of loops
Returns :
the average of theTab
"""
som = 0
n = 0
for i in theTab :
if i > 0 :
som += i
n += 1
elif i < 0:
raise Exception("No positive value found")
elif i == 0:
raise ZeroDivisionError("You can't divide by zero",ZeroDivisionError)
elif type(i) != "int" or i == None:
raise TypeError("Not an integer",TypeError)


Moy = som / n
return Moy

#////////////////////////////////////////////
def max_value(theTab):
"""
This function return the max value of the table

Parameters :
save: saves the highest number
Returns :
the highest number
"""
save = 0

for i in theTab :
if i > save :
save = i
return save

#////////////////////////////////////////////
def reverse_table(theTab):
"""
This function reverse the table

Returns :
the reverse of theTab
"""
for i in range(len(theTab)//2):
tmp = theTab[i]
endVal = len(theTab)-i-1
theTab[i] = theTab[endVal]
theTab[endVal] = tmp

#return theTab[::-1]
return theTab

#////////////////////////////////////////////
def roi_bbox(npTab:np.array):
"""
This function return a Bounding box

Parameters :
npTab: tab of a numpy array
matrice: all the coordonates of "1" in npTab
x,y: the max and min coordonates
Returns :
the coordinates max and min in x and y for
create a bounding box
"""
#x1 = None
#y1 = None
#x2 = None
#y2 = None

#for w in range(45,55):
# for h in range(60,85):
# npTab(h,w) = 1
# OU
npTab[60:85,45:55] = np.ones((25,10),dtype = float)

"""
matrice = np.argwhere(npTab == 1)
for i in matrice:
if x1 is None or i[0] < x1:
x1 = i[0]
if y1 is None or i[1] < y1:
y1 = i[1]
if x2 is None or i[0] > x2:
x2 = i[0]
if y2 is None or i[1] > y2:
y2 = i[1]
"""
lx, ly = np.where(npTab != 0)
if lx is None or ly is None:
raise ValueError('X or Y is null')
else:
return np.array([
[np.min(lx),np.min(ly)],
[np.max(lx),np.max(ly)]
])

#////////////////////////////////////////////
def alea(mini,maxi):
"""
This function generate a number

Parameters :
x: max number
Returns :
return random number
"""
return random.randint(mini, maxi)

#////////////////////////////////////////////
def random_fill_sparse(table:np.array,k:int):
"""
This function fill random cells with X

Parameters :
table: the empty table
k: number of 'X'
Returns :
return array with random cells fill with X
"""
for i in range(k):
table[alea(0,table.shape[0]-1),alea(0,table.shape[1]-1)] = 'X'

return table

#////////////////////////////////////////////
def remove_whitespace(phrase):
"""
This function remove all the whitespace of a string

Parameters :
phrase: the string
Returns :
return string whitout whitespace
"""
return phrase.replace(' ', '')

#////////////////////////////////////////////
def shuffle(list_in):
"""
This function remove all the whitespace of a string

Parameters :
phrase: the string
Returns :
return string whitout whitespace
"""
answer=[]
for i in range(len(list_in)):
random = alea(0,len(list_in)-1)
answer.append(list_in[random])
list_in.pop(random)
return answer


#////////////////////////////////////////////
theTab = [1,2,3,4,5,6,7,8,9]
print("Average : " + str(average_above_zero(theTab)))
'''
my_list=[0,2,-3]
average = average_above_zero(my_list)
print("T1 Average : " + str(average))
my_list=9
average = average_above_zero(my_list)
print("T2 Average : " + str(average))

'''
print("Max : " + str(max_value(theTab)))
print("Reverse : " + str(reverse_table(theTab)))
print("Bounding box : " + str(roi_bbox(np.zeros([100,100],dtype = float))))
print("random_fill_sparse : " + str(random_fill_sparse(np.empty([alea(1,10),alea(1,10)], dtype=str), alea(1,10))))
print("remove_whitespace : " + str(remove_whitespace("J'adore python, mettez moi 20, merci :D")))
print("shuffle : " + str(shuffle(theTab)))


102 changes: 102 additions & 0 deletions assignements/S1_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 16 11:18:16 2020

@author: bouvaran
"""
import random

#////////////////////////////////////////////
gameStart = False
human_score = 0
computer_score = 0
winner_score = 20
round_hu_comp = 0
pointParRound = 0
pointRoundEnd = 0
mini = 1
maxi = 6
comp_RoundMax = 3

def alea(mini,maxi):
return random.randint(mini, maxi)

def Menue(gameStart):
if gameStart == False:
print("Welcome to the dice game")
print("Do you want to play ? y / n ")

if input() == "y":
print("Let's go !")
gameStart = True
Start(gameStart,round_hu_comp,mini,maxi,comp_RoundMax,pointRoundEnd,human_score,computer_score)
else:
print("ok, bye")
raise SystemExit

def CountPoint(round_hu_comp,pointRoundEnd,human_score,computer_score):
if round_hu_comp == 0:
print("human round")
human_score = human_score + pointRoundEnd
print("Human score : " + str(human_score))
if human_score > winner_score:
print("YOU WIN")
raise SystemExit
return Start(True,1,mini,maxi,comp_RoundMax,pointRoundEnd,human_score,computer_score)
else :
print("computer round")
computer_score = computer_score + pointRoundEnd
print("Computer score : " + str(computer_score))
if computer_score > winner_score:
print("LOOOOOOSER")
raise SystemExit
return Start(True,0,mini,maxi,comp_RoundMax,pointRoundEnd,human_score,computer_score)


def Start(gameStart,round_hu_comp,mini,maxi,comp_RoundMax,pointRoundEnd,human_score,computer_score):
if gameStart == True:
if round_hu_comp == 0:
print("Do you want throw the dice ? y/n")
if input() == "y":
pointParRound = alea(mini,maxi)
print("dice = " + str(pointParRound))
if pointParRound == 1:
pointRoundEnd = 1
print("end of round, point won : " + str(pointRoundEnd))
human_score = pointRoundEnd
CountPoint(0,pointRoundEnd,human_score,computer_score)
else:
pointRoundEnd += pointParRound
Start(gameStart,round_hu_comp,mini,maxi,comp_RoundMax,pointRoundEnd,human_score,computer_score)
else:
print("end of round, point won : " + str(pointRoundEnd))
CountPoint(0,pointRoundEnd,human_score,computer_score)

else:
computer_Round = alea(1,comp_RoundMax)
for i in range(computer_Round):
pointParRound = alea(mini,maxi)
print("dice = " + str(pointParRound))
if pointParRound == 1:
pointRoundEnd = 1
computer_score = pointRoundEnd
CountPoint(1,pointRoundEnd,human_score,computer_score)
print("end of round, point won : " + str(pointRoundEnd))
else:
pointRoundEnd += pointParRound
print("end of round, point won : " + str(pointRoundEnd))
computer_score = pointRoundEnd
CountPoint(1,pointRoundEnd,human_score,computer_score)
else:
raise ValueError("Error, the game can't start")



Menue(gameStart)







Loading