-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPlayer.go
More file actions
94 lines (81 loc) · 1.92 KB
/
Player.go
File metadata and controls
94 lines (81 loc) · 1.92 KB
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
//Participating Game of Drones by CodinGame
package main
import "fmt"
// import "os"
const (
DEBUG = false //True iff traces are activated
ZONE_RADIUS = 100 //Radius of the zones
)
var (
players []player //all the player of drones. Array index = player's ID
whoami int //index of my player in the array of players
zones []zone //all game zones
)
type point struct {
x, y int
}
type player struct {
drones []point //position of each drone
}
//Contains the center of the zone and current owner
type zone struct {
pos point
owner int
}
func newZone() zone {
return zone{point{-1, -1}, -1}
}
//Reads the game initialization information
func readInit() {
var numPlayers, numZones, numDronesPerplayer int
fmt.Scanf("%d %d %d %d\n", &numPlayers, &whoami, &numDronesPerplayer, &numZones)
players = make([]player, numPlayers)
for i, _ := range players {
players[i].drones = make([]point, numDronesPerplayer)
}
zones = make([]zone, numZones)
for i, _ := range zones {
zones[i] = newZone()
fmt.Scanf("%d %d\n", &zones[i].pos.x, &zones[i].pos.y)
}
}
//Reads the information of a turn
func parseTurn() bool {
for i, _ := range zones {
_, err := fmt.Scanf("%d\n", &zones[i].owner)
if err != nil {
fmt.Println("Error reading turn zones owners:", err)
return false
}
}
for i, _ := range players {
for j, _ := range players[i].drones {
_, err := fmt.Scanf("%d %d\n", &players[i].drones[j].x, &players[i].drones[j].y)
if err != nil {
fmt.Println("Error reading turn drones:", err)
return false
}
}
}
return true
}
//Prints the movements of own drones
func play() {
// Do not move any drone
for _, d := range players[whoami].drones {
fmt.Println(d.x, d.y)
}
}
func main() {
readInit()
debug("Current status:", players, whoami, zones)
for parseTurn() {
debug("Current status:", players, whoami, zones)
play()
}
}
func debug(x ...interface{}) {
if DEBUG {
fmt.Println(x)
}
}