Initial version
[battleship.git] / battleship.py
1 #!/usr/bin/env python3
2 # -*- coding: utf8 -*-
3
4 # Programme de Bataille Navale
5 #
6 # Codé par Lucie Mazet
7 #
8 # Janvier 2024
9
10 # Constants
11
12 N = 10
13
14 tab_human = []
15
16 tab_machine = []
17
18 ships = [1, 1, 1, 1, 2, 2, 3]
19
20 # value in tab
21 # S: ship position
22 # O: bomb missed
23 # X: ship hit
24
25 # init table
26 def init_table(tab):
27 return
28
29 # display table
30 def display(main_tab, second_tab=[]):
31
32 # display all symbols in main tab
33 print("foobar")
34
35 # if defined
36 if len(second_tab) != 0:
37 # only display 'O' and 'X'
38 pass
39
40 return
41
42 # read coordonate
43 def read_coordonate(size, tab):
44 return []
45
46 # generate coordonate
47 def generate_coordonate(size, tab):
48 return []
49
50 # put element into table
51 def put_in_table(element, pos, tab):
52 return
53
54 # check table status
55 def check_status(tab):
56 return True
57
58 # main function
59 def main():
60
61 # init table for human
62 init_table(tab_human)
63 for ship in ships:
64 display(tab_human)
65 print("Where do you want to place a ship of", ship, "?")
66 pos = read_coordonate(ship, tab_human)
67 put_in_table('S', pos, tab_human)
68
69 # init table for machine
70 init_table(tab_machine)
71 for ship in ships:
72 display(tab_machine)
73 pos = generate_coordonate(ship, tab_machine)
74 put_in_table('S', pos, tab_machine)
75
76 # main loop
77 while True:
78
79 # humain play
80 display(tab_human, tab_machine)
81 print("Where do you want to bomb?")
82 pos = read_coordonate(1, tab_machine)
83 put_in_table('B', pos, tab_machine)
84 if check_status(tab_machine):
85 print("Humain won")
86 display(tab_machine)
87 exit(0)
88
89 # machine play
90 pos = generate_coordonate(1, tab_human)
91 put_in_table('B', pos, tab_human)
92 if check_status(tab_human):
93 print("Machine won")
94 display(tab_human)
95 exit(0)
96
97 exit(1)
98
99 # exec main funtion
100 if __name__ == "__main__":
101 main()
102
103 # vim: set ts=4 sw=4 et: