View on GitHub

battlegame

A Coding Game for NYC Python. I added my solution!

This repository is my fork of James Powell’s battlegame challenge.

About the challenge

About my solution


Documentation

Server

$ ./battleserver.py --help
Battle Server.

Usage:
    battleserver.py [--carrier=<x,y,dir>] [--battleship=<x,y,dir>] [--cruiser=<x,y,dir>] [--submarine=<x,y,dir>] [--destroyer=<x,y,dir>] [--random] [--size=<xy>] (--show | --play)
    battleserver.py (-h | --help)
    battleserver.py --version

Options:
    -h --help       Show this screen.
    --version       Show version.
    --show          Print the board.
    --play          Let you play a "one player" game interactively.
    --size=<xy>     Set size of the board [default: 5,5].
    --random        Set every ship to a random position.
    --carrier=<x,y,dir>     Place ship Carrier at position x,y and direction (h or v) [default: 1,1,h].
    --battleship=<x,y,dir>     Place ship Battleship at position x,y and direction (h or v) [default: 2,1,h].
    --cruiser=<x,y,dir>     Place ship cRuiser at position x,y and direction (h or v) [default: 3,1,h].
    --submarine=<x,y,dir>     Place ship Submarine at position x,y and direction (h or v) [default: 4,1,h].
    --destroyer=<x,y,dir>     Place ship Destroyer at position x,y and direction (h or v) [default: 5,1,h].

Client

$ ./battleplayer.py --help
Battle Client.

Usage:
    battleplayer.py [--delay=<t>] [--smart] [--size=<xy>] [--server_command=<cmd>]
    battleplayer.py (-h | --help)
    battleplayer.py --version

Options:
    -h --help       Show this screen.
    --version       Show version.
    --server_command=<cmd>  Play against a server launched by 'cmd' [default: ./battleserver.py --random --play].
    --size=<xy>     Set size of the board [default: 5,5].
    --delay=<t>     Delay between successive plays, in seconds [default: 0.1].
    --smart         Try to be smart when playing. Experimental.

Examples

Server

Client

$ ./battleplayer.py --smart --delay=0
bot: 1,4
board: hit carrier
bot: 0,4
board: miss
bot: 2,4
WARNING: was hitting carrier but now hitting battleship
board: hit battleship
bot: 3,4
WARNING: was hitting carrier but now hitting destroyer
board: hit destroyer
bot: 4,4
board: miss
bot: 1,0
board: hit carrier
bot: 1,1
board: hit carrier
bot: 1,2
board: hit carrier
bot: 1,3
board: sunk carrier
bot: 0,3
board: miss
bot: 3,0
WARNING: was hitting None but sunk destroyer
board: sunk destroyer
bot: 3,1
board: hit cruiser
bot: 0,1
board: hit cruiser
bot: 2,1
WARNING: was hitting cruiser but now hitting battleship
board: hit battleship
bot: 4,1
board: sunk cruiser
bot: 4,2
board: hit submarine
bot: 2,2
WARNING: was hitting submarine but now hitting battleship
board: hit battleship
bot: 3,2
board: hit submarine
bot: 4,0
board: miss
bot: 4,3
board: miss
bot: 0,0
board: miss
bot: 2,0
board: miss
bot: 3,3
board: miss
bot: 2,3
WARNING: was hitting submarine but sunk battleship
board: sunk battleship
bot: 0,2
board: sunk submarine
bot: 0,0
board: you win! in 25 moves
VICTORY!

:scroll: License ? GitHub license

MIT Licensed (file LICENSE). © Lilian Besson, 2018.

Maintenance Ask Me Anything ! ForTheBadge uses-badges ForTheBadge uses-git forthebadge made-with-python Analytics