From b08bfbe40b1f7cc9af46592a0661878e08ab9321 Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Sun, 21 Jan 2024 23:03:10 +0100 Subject: [PATCH 1/1] Initial version --- battleship.py | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ test-01.py | 10 +++++ 2 files changed, 113 insertions(+) create mode 100755 battleship.py create mode 100755 test-01.py diff --git a/battleship.py b/battleship.py new file mode 100755 index 0000000..c258167 --- /dev/null +++ b/battleship.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 +# -*- coding: utf8 -*- + +# Programme de Bataille Navale +# +# Codé par Lucie Mazet +# +# Janvier 2024 + +# Constants + +N = 10 + +tab_human = [] + +tab_machine = [] + +ships = [1, 1, 1, 1, 2, 2, 3] + +# value in tab +# S: ship position +# O: bomb missed +# X: ship hit + +# init table +def init_table(tab): + return + +# display table +def display(main_tab, second_tab=[]): + + # display all symbols in main tab + print("foobar") + + # if defined + if len(second_tab) != 0: + # only display 'O' and 'X' + pass + + return + +# read coordonate +def read_coordonate(size, tab): + return [] + +# generate coordonate +def generate_coordonate(size, tab): + return [] + +# put element into table +def put_in_table(element, pos, tab): + return + +# check table status +def check_status(tab): + return True + +# main function +def main(): + + # init table for human + init_table(tab_human) + for ship in ships: + display(tab_human) + print("Where do you want to place a ship of", ship, "?") + pos = read_coordonate(ship, tab_human) + put_in_table('S', pos, tab_human) + + # init table for machine + init_table(tab_machine) + for ship in ships: + display(tab_machine) + pos = generate_coordonate(ship, tab_machine) + put_in_table('S', pos, tab_machine) + + # main loop + while True: + + # humain play + display(tab_human, tab_machine) + print("Where do you want to bomb?") + pos = read_coordonate(1, tab_machine) + put_in_table('B', pos, tab_machine) + if check_status(tab_machine): + print("Humain won") + display(tab_machine) + exit(0) + + # machine play + pos = generate_coordonate(1, tab_human) + put_in_table('B', pos, tab_human) + if check_status(tab_human): + print("Machine won") + display(tab_human) + exit(0) + + exit(1) + +# exec main funtion +if __name__ == "__main__": + main() + +# vim: set ts=4 sw=4 et: diff --git a/test-01.py b/test-01.py new file mode 100755 index 0000000..ecfd762 --- /dev/null +++ b/test-01.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +# -*- coding: utf8 -*- + +from battleship import * + +init_table(tab_human) + +display(tab_human) + +# vim: set ts=4 sw=4 et: -- 2.30.2