summaryrefslogtreecommitdiff
path: root/aesthetics.go
blob: 5d580f6e3c8d07cff960f1b66c355c72ff8fdc69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package main

import (
	"strconv"
)

// printPrimary displays an ASCII version of the primary battleship board
// The primary board is the one which belongs to the person calling a hit
// He sees his own boats on this board.
// Here is an example
//   A B C D E F G H I J
// 0 ~ ~ ~ ~ ~ ~ ~ ~ ~ △
// 1 ~ ~ ~ ~ ~ ~ ~ ~ ~ ▯
// 2 ~ ~ ~ ~ ~ ~ ~ ~ ~ ▽
// 3 ~ ~ ~ ◁ ▭ ▭ ▭ ▷ ~ ~
// 4 ~ ~ △ ~ ~ ~ ~ △ ~ ~
// 5 ~ ~ ▯ ~ ~ ~ ~ ▯ ~ ~
// 6 ~ ~ ▯ ~ ~ ~ ~ ~ ~ ~
// 7 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 8 ~ ~ ~ ~ ◀ ▬ ▬ ▷ ~ ~
// 9 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// Only E8, F8, and G8 were hit.
func (plyr player) PrimaryDisplay() string {
	text := "\n  A B C D E F G H I J \n"
	for i := 0; i < 10; i++ {
		text += strconv.Itoa(i)
		text += " "
		for j := 0; j < 10; j++ {
			switch plyr.primary[i][j][2] {
			case 0: // That coordinate was not hit
				text += boatchars[1][plyr.primary[i][j][1]]
			case 1: // That coordinates was hit
				text += boatchars[0][plyr.primary[i][j][1]]
				// default:
				// 	return errors.New("Unknown State (hit/unhit) at a given coordinate")
			}
			text += " "
		}
		text += "\n"
	}
	// fmt.Println(text)
	return text
}

// printTarget displays an ASCII version of the target battleship board
// The target board is the one which shows a player what he knows about
// his opponent. This is the board a player would play on.
// Here is an example
// A B C D E F G H I J
// 0 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 1 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 2 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 3 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 4 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 5 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 6 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 7 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// 8 ~ ~ ~ ~ ▣ ▣ ▣ ~ ~ ~
// 9 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// Since the boat in F8, E8, G8 is not sunk, The player does not see
// it's shape. Upon sinking it, he will be able to see it.
func (plyr player) TargetDisplay() string {
	text := "\n  A B C D E F G H I J \n"
	for i := 0; i < 10; i++ {
		text += strconv.Itoa(i)
		text += " "
		for j := 0; j < 10; j++ {
			switch plyr.target[i][j][0] {
			case 0:
				text += boatchars[1][0]
			case 1:
				if plyr.gains[plyr.prey.primary[i][j][0]] {
					text += boatchars[0][plyr.prey.primary[i][j][1]]
				} else {
					switch plyr.prey.primary[i][j][0] {
					case 0:
						text += boatchars[0][0]
					default:
						text += mistery_hit
					}
				}
			}
			text += " "
		}
		text += "\n"
	}
	// fmt.Println(text)
	return text
}

// printPrimary displays using ASCII art the primary battleship board
func (plyr player) PrimarySlice() []string {
	board := []string{
		" ",
		"A",
		"B",
		"C",
		"D",
		"E",
		"F",
		"G",
		"H",
		"I",
		"J",
	}
	for i := 0; i < 10; i++ {
		board = append(board, strconv.Itoa(i))
		for j := 0; j < 10; j++ {
			switch plyr.primary[i][j][2] {
			case 0: // That coordinate was not hit
				board = append(board, boatchars[1][plyr.primary[i][j][1]])
			case 1: // That coordinates was hit
				board = append(board, boatchars[0][plyr.primary[i][j][1]])
				// default:
				// 	return errors.New("Unknown State (hit/unhit) at a given coordinate")
			}
		}
	}
	// fmt.Println(text)
	return board
}

func (plyr player) TargetSlice() []string {
	board := []string{
		" ",
		"A",
		"B",
		"C",
		"D",
		"E",
		"F",
		"G",
		"H",
		"I",
		"J",
	}
	for i := 0; i < 10; i++ {
		board = append(board, strconv.Itoa(i))
		for j := 0; j < 10; j++ {
			switch plyr.target[i][j][0] {
			case 0:
				board = append(board, boatchars[1][0])
			case 1:
				if plyr.gains[plyr.prey.primary[i][j][0]] {
					board = append(board, boatchars[0][plyr.prey.primary[i][j][1]])
				} else {
					switch plyr.prey.primary[i][j][0] {
					case 0:
						board = append(board, boatchars[0][0])
					default:
						board = append(board, mistery_hit)
					}
				}
			}
		}
	}
	return board
}

// TODO: Function which returns what was hit as a commentary for the hitter

/* Boats Info:
   |------------+--------+----------------|
   | BoatName   | BoatID | HorizontalBoat |
   | Carrier    | 0      | ◁ ▭ ▭ ▭ ▷      |
   | Battleship | 1      | ◁ ▭ ▭ ▷        |
   | Destroyer  | 2      | ▭ ▭ ▷          |
   | Submarine  | 3      | ◁ ▭ ▷          |
   | PatrolBoat | 4      | ▭ ▷            |
   |------------+--------+----------------|
*/
var boatchars = [2][7]string{
	{`◌`, `▲`, `▼`, `◀`, `►`, `▮`, `▬`},
	{`~`, `△`, `▽`, `◁`, `▷`, `▯`, `▭`},
}

// This constant keeps information about boats that aren't totally sunk secret.
// It therefore substitues the shape of a boat on the target board when it is unsunk.
const mistery_hit = `▣`