Skip to content
Snippets Groups Projects
Commit 952d2fcf authored by Garance Guey's avatar Garance Guey
Browse files

commentaire

parent 2864c681
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,8 @@
<list>
<option value="W29" />
<option value="E501" />
<option value="W29" />
<option value="E501" />
</list>
</option>
</inspection_tool>
......
......@@ -2,8 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="a1e637b1-c555-4557-a6ba-8dfbc46c2cef" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/game2048/tb_grid_2048.py" beforeDir="false" afterPath="$PROJECT_DIR$/game2048/grid_2048.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/game2048/tb_test_grid_2048.py" beforeDir="false" afterPath="$PROJECT_DIR$/game2048/test_grid_2048.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/Project_Default.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/game2048/grid_2048.py" beforeDir="false" afterPath="$PROJECT_DIR$/game2048/grid_2048.py" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
......@@ -42,40 +43,94 @@
</counts>
</usages-collector>
</session>
<session id="-897679322">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.6" value="1" />
<entry key="project.open.time.7" value="1" />
<entry key="project.opened" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="py" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="Python" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="Python Console" value="38" />
<entry key="py" value="1757" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="Python" value="1795" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/game2048/grid_2048.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="4" column="19" selection-start-line="4" selection-start-column="19" selection-end-line="4" selection-end-column="19" />
<state relative-caret-position="349">
<caret line="126" column="34" selection-start-line="126" selection-start-column="34" selection-end-line="126" selection-end-column="34" />
<folding>
<marker date="1542184310612" expanded="true" signature="3334:3339" ph="..." />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game2048/textual_2048.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/game2048/test_textual_2048.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/game2048/textual_2048.py" />
<option value="$PROJECT_DIR$/game2048/test_textual_2048.py" />
<option value="$PROJECT_DIR$/game2048/grid_2048.py" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="1056" />
<option name="width" value="756" />
<option name="height" value="1032" />
<component name="ProjectFrameBounds">
<option name="x" value="1069" />
<option name="width" value="1085" />
<option name="height" value="1391" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Course" />
<pane id="ProjectPane">
<subPane>
<expand>
......@@ -88,20 +143,14 @@
<item name="2048" type="462c0819:PsiDirectoryNode" />
<item name="game2048" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="2048" type="b2602c69:ProjectViewProjectNode" />
<item name="2048" type="462c0819:PsiDirectoryNode" />
<item name="textual2048" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Course" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../2048 local" />
<property name="settings.editor.selected.configurable" value="com.jetbrains.python.configuration.PyActiveSdkModuleConfigurable" />
</component>
<component name="RunDashboard">
......@@ -116,24 +165,52 @@
</list>
</option>
</component>
<component name="RunManager">
<configuration name="grid_2048" type="PythonConfigurationType" factoryName="Python" temporary="true">
<module name="2048" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/game2048" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/game2048/grid_2048.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.grid_2048" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="ToolWindowManager">
<frame x="-7" y="-7" width="1295" height="695" extended-state="6" />
<frame x="713" y="0" width="723" height="927" extended-state="0" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24960254" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.12244898" />
<window_info id="Structure" order="1" weight="0.25" />
<window_info anchor="bottom" id="Version Control" />
<window_info anchor="bottom" id="Python Console" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32955974" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Python Console" order="8" weight="0.32955974" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
......@@ -145,10 +222,19 @@
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/game2048/grid_2048.py">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="68">
<caret line="4" column="19" selection-start-line="4" selection-start-column="19" selection-end-line="4" selection-end-column="19" />
<state relative-caret-position="349">
<caret line="126" column="34" selection-start-line="126" selection-start-column="34" selection-end-line="126" selection-end-column="34" />
<folding>
<marker date="1542184310612" expanded="true" signature="3334:3339" ph="..." />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/game2048/textual_2048.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/game2048/test_textual_2048.py">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</component>
</project>
\ No newline at end of file
......@@ -2,66 +2,126 @@ import random as rd
THEMES = {"0": {"name": "Default", 0: "", 2: "2", 4: "4", 8: "8", 16: "16", 32:"32", 64: "64", 128: "128", 256: "256", 512: "512", 1024: "1024", 2048: "2048",4096: "4096", 8192: "8192"}, "1": {"name": "Chemistry", 0: "", 2: "H", 4: "He", 8:"Li", 16: "Be", 32: "B", 64: "C", 128: "N", 256: "O", 512: "F", 1024: "Ne", 2048:"Na", 4096: "Mg", 8192: "Al"}, "2": {"name": "Alphabet", 0: "", 2: "A", 4: "B", 8:"C", 16: "D", 32: "E", 64: "F", 128: "G", 256: "H", 512: "I", 1024: "J", 2048: "K",4096: "L", 8192: "M"}}
#FONCTIONNALITE 1
def create_grid(n):
game_grid = []
for i in range(n):
game_grid.append([' ']*n)
return game_grid
#crée le bon nombre de ligne
game_grid.append([' ']*n) #crée le bon nombre de colonnes
return (game_grid)
def get_value_new_tile():
#choisi la valeur de la nouvelle case avec la probabilté indiquée dans l'énoncé
return rd.choice([2,2,2,2,2,2,2,2,2,4])
def get_all_tiles(grid):
tiles = []
for line in grid:
for tile in line:
if tile == ' ': tiles.append(0)
for line in grid: #parcours toutes les lignes
for tile in line: #parcours toutes les colonnes
if tile == ' ': tiles.append(0) #traite le cas particulier de la double notation 0 ou " " pour les emplacments vides
else: tiles.append(tile)
return tiles
def get_empty_tiles_positions(grid):
empty_tiles = []
n = len(grid)
m = len(grid[0])
for i in range(n):
for j in range(m):
nb_ligne = len(grid)
nb_colonne = len(grid[0])
#on suppose que la grille a au moins une ligne
#on suppose que toutes les lignes ont le même nombre de colonnes
for i in range(nb_ligne):
for j in range(nb_colonne):
if grid[i][j] == ' ' or grid[i][j] == 0:
#traite le cas particulier de la double notation 0 ou " " pour les emplacments vides
empty_tiles.append((i,j))
return empty_tiles
def get_new_position(grid):
#choisi une postion au hasard parmis les position libre
empty_tiles = get_empty_tiles_positions(grid)
return rd.choice(empty_tiles)
return (rd.choice(empty_tiles))
def grid_get_value(grid,x,y):
if grid[x][y] == ' ':
#traite le cas particulier de la double notation 0 ou " "
return 0
return grid[x][y]
def grid_add_new_tile(grid):
x,y = get_new_position(grid)
grid[x][y] = get_value_new_tile()
#attention, la fonction modifie la liste passée en argument !
return grid
def init_game(n):
grid = create_grid(n)
for i in range(2):
for new_tile in range(2):
grid = grid_add_new_tile(grid)
return grid
#FONCTIONNALITE 2
def grid_to_string_with_size_and_theme(grid, theme,n):
m = long_value_with_theme(grid,theme)
a = ""
for i in range(n):
a += (" " + "="*(m+2))*n + "\n"
for j in range(n):
a += "| {}".format(theme[grid[i][j]]) + " "*(1 + m - len(theme[grid[i][j]]))
a += "|\n"
a += (" " + "="*(m+2))*n
return a
longest_str = long_value_with_theme(grid,theme)
affichage = ""
for ligne in range(n):
#création de la délimation du dessus
affichage += (" " + "="*(longest_str+2))*n + "\n"
#calcul du nombre nécéssaire d'espaces
for colonne in range(n):
affichage += "| {}".format(theme[grid[ligne][colonne]]) + " "*(1 + longest_str - len(theme[grid[ligne][colonne]]))
affichage += "|\n" #fini la ligne
#création de la dernière délimation du bas
affichage += (" " + "="*(longest_str+2))*n
return affichage
def long_value_with_theme(grid,theme):
return max(len(theme[v]) for v in get_all_tiles(grid))
grid=[[16, 4, 8, 2], [2, 4, 2, 128], [4, 512, 32, 64], [1024, 2048, 512, 2]]
print(grid_to_string_with_size_and_theme(grid,THEMES["1"],4))
#TEST
"""grid=[[16, 4, 8, 2], [2, 4, 2, 128], [4, 512, 32, 64], [1024, 2048, 512, 2]]
print(grid_to_string_with_size_and_theme(grid,THEMES["1"],4)"""
#FONCTIONNALITE 4
"""def move_row_left(row):
n=len(row)
row_without_zero=[]
for i in range (n):
if row[i]!= 0:
row_without_zero.append(row[i])
n_bis=len(row_without_zero)
print(row_without_zero)
row_fusion=[]
indice=0
while indice < n_bis-1 :
if row_without_zero[indice]==row_without_zero[indice+1]:
row_fusion.append(row_without_zero[indice]*2)
row_without_zero.pop(indice+1)
n_bis=n_bis-1
print(row_fusion)
elif indice+1 < n_bis-1:
row_fusion.append(row_without_zero[indice])
print(row_fusion)
elif indice+1==n_bis :
row_fusion.append(row_without_zero[indice])
row_fusion.append(row_without_zero[indice+1])
indice=indice+1
n_fusion=len(row_fusion)
row_final=[0]*4
for tile in range (n_fusion):
row_final[tile]=row_fusion[tile]
return(row_final)
print(move_row_left([2,4,2,0]))"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment