Skip to content

Commit e02fa99

Browse files
author
Mark Charlton
committed
Wk8 battleships working. 1 bug in find_space left
1 parent bc77ecd commit e02fa99

File tree

171 files changed

+36200
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+36200
-0
lines changed

.history/Assessment/Wk8/destroyer_20230314234043.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# single ship battleship game.
2+
3+
# inits
4+
board_width=5
5+
board_height=5
6+
7+
# Build the array of ships
8+
ships=[1]
9+
ships.append(2, [[2,2],[2,3]])
10+
11+
print ( ships )
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# single ship battleship game.
2+
3+
# inits
4+
board_width=5
5+
board_height=5
6+
7+
# Build the array of ships
8+
ships=[1]
9+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
10+
11+
print ( ships )
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# single ship battleship game.
2+
3+
def init_board(bw, bh):
4+
board=[]
5+
for x in range(bh):
6+
board[x]=[]
7+
for y in range(bw):
8+
board[x][y]=" "
9+
return board
10+
11+
def print_board(board, bw, bh):
12+
13+
print (" ", end='')
14+
for y in range(1,bw+1):
15+
print ( f' {y} ' )
16+
17+
for x in board:
18+
print ( f'{x} ')
19+
for y in board[x]:
20+
print ( f'[{board[x][y]}]', end='')
21+
print ( "" )
22+
23+
# inits
24+
board_width=5
25+
board_height=5
26+
27+
# Build the array of ships
28+
ships=[1]
29+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
30+
31+
print ( ships )
32+
33+
#
34+
# Setup the game
35+
#
36+
board=init_board(board_width, board_height)
37+
38+
print_board ( board )
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# single ship battleship game.
2+
3+
def init_board(bw, bh):
4+
board=[]
5+
for x in range(bh):
6+
for y in range(bw):
7+
board[x][y]=" "
8+
return board
9+
10+
def print_board(board, bw, bh):
11+
12+
print (" ", end='')
13+
for y in range(1,bw+1):
14+
print ( f' {y} ' )
15+
16+
for x in board:
17+
print ( f'{x} ')
18+
for y in board[x]:
19+
print ( f'[{board[x][y]}]', end='')
20+
print ( "" )
21+
22+
# inits
23+
board_width=5
24+
board_height=5
25+
26+
# Build the array of ships
27+
ships=[1]
28+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
29+
30+
print ( ships )
31+
32+
#
33+
# Setup the game
34+
#
35+
board=init_board(board_width, board_height)
36+
37+
print_board ( board )
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# single ship battleship game.
2+
3+
def init_board(bw, bh):
4+
board=[[' ' for j in range(bw)] for i in range(bh)]
5+
return board
6+
7+
def print_board(board, bw, bh):
8+
9+
print (" ", end='')
10+
for y in range(1,bw+1):
11+
print ( f' {y} ' )
12+
13+
for x in board:
14+
print ( f'{x} ')
15+
for y in board[x]:
16+
print ( f'[{board[x][y]}]', end='')
17+
print ( "" )
18+
19+
# inits
20+
board_width=5
21+
board_height=5
22+
23+
# Build the array of ships
24+
ships=[1]
25+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
26+
27+
print ( ships )
28+
29+
#
30+
# Setup the game
31+
#
32+
board=init_board(board_width, board_height)
33+
34+
print ( board )
35+
36+
print_board ( board )
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# single ship battleship game.
2+
3+
import pprint as pp
4+
5+
def init_board(bw, bh):
6+
board=[[' ' for j in range(bw)] for i in range(bh)]
7+
return board
8+
9+
def print_board(board, bw, bh):
10+
11+
print (" ", end='')
12+
for y in range(1,bw+1):
13+
print ( f' {y} ' )
14+
15+
for x in board:
16+
print ( f'{x} ')
17+
print ( x + '[' + '] ['.join(board[x]) + ']')
18+
# for y in board[x]:
19+
# print ( f'[{board[x][y]}]', end='')
20+
print ( "" )
21+
22+
# inits
23+
board_width=5
24+
board_height=5
25+
26+
# Build the array of ships
27+
ships=[1]
28+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
29+
30+
print ( ships )
31+
32+
#
33+
# Setup the game
34+
#
35+
board=init_board(board_width, board_height)
36+
37+
print ( board )
38+
39+
print_board ( board, bw, bh )
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# single ship battleship game.
2+
3+
import pprint as pp
4+
5+
def init_board(bw, bh):
6+
board=[[' ' for j in range(bw)] for i in range(bh)]
7+
return board
8+
9+
def print_board(board, bw, bh):
10+
11+
print (" ", end='')
12+
for y in range(1,bw+1):
13+
print ( f' {y} ' )
14+
15+
for x in board:
16+
print ( f'{x} ')
17+
print ( x + '[' + '] ['.join(board[x]) + ']')
18+
# for y in board[x]:
19+
# print ( f'[{board[x][y]}]', end='')
20+
print ( "" )
21+
22+
# inits
23+
board_width=5
24+
board_height=5
25+
26+
# Build the array of ships
27+
ships=[1]
28+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
29+
30+
print ( ships )
31+
32+
#
33+
# Setup the game
34+
#
35+
board=init_board(board_width, board_height)
36+
37+
print ( board )
38+
39+
print_board ( board, board_width, board_height )
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# single ship battleship game.
2+
3+
import pprint as pp
4+
5+
def init_board(bw, bh):
6+
board=[[' ' for j in range(bw)] for i in range(bh)]
7+
return board
8+
9+
def print_board(board, bw, bh):
10+
11+
print (" ", end='')
12+
for y in range(1,bw+1):
13+
print ( f' {y} ' )
14+
15+
for x in board:
16+
print ( f'{x} ', end='')
17+
print ( x + '[' + '] ['.join(board[x]) + ']')
18+
# for y in board[x]:
19+
# print ( f'[{board[x][y]}]', end='')
20+
print ( "" )
21+
22+
# inits
23+
board_width=5
24+
board_height=5
25+
26+
# Build the array of ships
27+
ships=[1]
28+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
29+
30+
print ( ships )
31+
32+
#
33+
# Setup the game
34+
#
35+
board=init_board(board_width, board_height)
36+
37+
print ( board )
38+
39+
print_board ( board, board_width, board_height )
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# single ship battleship game.
2+
3+
import pprint as pp
4+
5+
def init_board(bw, bh):
6+
board=[[' ' for j in range(bw)] for i in range(bh)]
7+
return board
8+
9+
def print_board(board, bw, bh):
10+
11+
print (" ", end='')
12+
for y in range(1,bw+1):
13+
print ( f' {y} ' )
14+
15+
for x in range(1,bw+1):
16+
print ( f'{x} ', end='')
17+
print ( x + '[' + '] ['.join(board[x]) + ']')
18+
# for y in board[x]:
19+
# print ( f'[{board[x][y]}]', end='')
20+
21+
22+
# inits
23+
board_width=5
24+
board_height=5
25+
26+
# Build the array of ships
27+
ships=[1]
28+
ships.append({"Length": 2, "Locn": [[2,2],[2,3]]})
29+
30+
print ( ships )
31+
32+
#
33+
# Setup the game
34+
#
35+
board=init_board(board_width, board_height)
36+
37+
print ( board )
38+
39+
print_board ( board, board_width, board_height )

0 commit comments

Comments
 (0)