Gérald LEBAN 3 years ago
parent
commit
b951a51d82
2 changed files with 0 additions and 129 deletions
  1. 0
    55
      game.py
  2. 0
    74
      marinbad/func.py

+ 0
- 55
game.py View File

@@ -1,55 +0,0 @@
1
-from player import get_player_move
2
-from random import shuffle
3
-
4
-
5
-drug = [3, 5, 7]
6
-
7
-playerType = {
8
-    "human": get_player_move
9
-}
10
-
11
-players = [
12
-    {
13
-        "name": "Joueur 1",
14
-        "type": "human"
15
-    },
16
-    {
17
-        "name": "Joueur 2",
18
-        "type": "human"
19
-    }
20
-]
21
-
22
-
23
-def show_current_game():
24
-    print("=============")
25
-    for index, val in enumerate(drug):
26
-        print(f"L{index + 1}: {'o' * val}")
27
-    print("=============")
28
-
29
-
30
-def execute_move(row, value, name):
31
-    drug[row] -= value
32
-    print(f"{name} a enlevé {value} allumettes(s) sur la ligne L{row + 1}")
33
-
34
-
35
-def play(name, type_):
36
-    show_current_game()
37
-    execute_move(*playerType[type_](name, drug), name)
38
-    if sum(drug) == 0:
39
-        show_current_game()
40
-        print(f"{name} à gangné !!")
41
-        return True
42
-    else:
43
-        return False
44
-
45
-
46
-# Choisi au hasard le premier joueur
47
-shuffle(players)
48
-
49
-# Affiche l'ordre de jeu
50
-print(f"Voici l'ordre des joueurs: {' => '.join([player['name'] for player in players])}")
51
-
52
-while True:
53
-    for player in players:
54
-        if play(player["name"], player["type"]):
55
-            exit(0)

+ 0
- 74
marinbad/func.py View File

@@ -1,74 +0,0 @@
1
-def toBin(integer):
2
-    """
3
-    Convert a decimal integer into a binary"
4
-    :param integer: the integer to be converted
5
-    :type integer int
6
-    :return: int
7
-    """
8
-    return int(str(bin(integer))[2:])
9
-
10
-
11
-def toDec(binVal):
12
-    """
13
-    Convert a binary value to a decimal value
14
-    :param binVal: The bin value to be converted
15
-    :type binVal: int, str
16
-    :return: int
17
-    """
18
-    return int(str(binVal), 2)
19
-
20
-
21
-def toBinArray(array):
22
-    """
23
-    Turn an array of decimal into an array of binary
24
-    :param array:
25
-    :return:
26
-    """
27
-    return [toBin(el) for el in array]
28
-
29
-
30
-def computeS(array):
31
-    """
32
-    Sum all values in an array
33
-    :param array: the array to compute on
34
-    :type array: list
35
-    :return: int
36
-    """
37
-    return sum(array)
38
-
39
-
40
-def nimSomme(integer):
41
-    """Return an array with 0 if element is even, 1 otherwise"""
42
-    return [int(el) % 2 for el in str(integer)]
43
-
44
-
45
-def isSafe(array):
46
-    """
47
-    Return True if value computed from the array is zero, False otherwise
48
-    :param array: the array to compute
49
-    :type array: list
50
-    :return: bool
51
-    """
52
-    def list2str(array):
53
-        a = ""
54
-        for el in array:
55
-            a += str(el)
56
-        return a
57
-
58
-    binString = list2str([int(el) % 2 for el in list2str(array)])
59
-    return toDec(binString) == 0
60
-
61
-
62
-array = [3, 5, 7]
63
-
64
-binArr = toBinArray(array)
65
-print("Bin Array: ", binArr)
66
-
67
-S = computeS(binArr)
68
-print("S: ", S)
69
-
70
-nimS = nimSomme(S)
71
-print("Somme de NIM: ", nimS)
72
-
73
-safe = isSafe(nimS)
74
-print("Safe: ", safe)

Loading…
Cancel
Save