Browse Source

Add score counting

Guillaume Koenig 7 years ago
parent
commit
da36d98e98
1 changed files with 9 additions and 1 deletions
  1. 9 1
      main.go

+ 9 - 1
main.go

@@ -75,14 +75,19 @@ type Car struct {
75
 	Arrival int
75
 	Arrival int
76
 	X       int
76
 	X       int
77
 	Y       int
77
 	Y       int
78
+
79
+	score int
78
 }
80
 }
79
 
81
 
80
 func (c *Car) Update(r *Ride) {
82
 func (c *Car) Update(r *Ride) {
81
 	c.moveTo(r.a, r.b)
83
 	c.moveTo(r.a, r.b)
82
-	if c.Arrival < r.s {
84
+	if c.Arrival <= r.s {
83
 		c.Arrival = r.s
85
 		c.Arrival = r.s
86
+		// count bonus points for being on time
87
+		c.score += B
84
 	}
88
 	}
85
 	c.moveTo(r.x, r.y)
89
 	c.moveTo(r.x, r.y)
90
+	c.score += r.length()
86
 	c.Rides = append(c.Rides, r.ID)
91
 	c.Rides = append(c.Rides, r.ID)
87
 }
92
 }
88
 
93
 
@@ -194,13 +199,16 @@ func solve() {
194
 	for assign() {
199
 	for assign() {
195
 	}
200
 	}
196
 
201
 
202
+	totalScore := 0
197
 	for _, c := range Cars {
203
 	for _, c := range Cars {
198
 		fmt.Fprintf(output, "%d", len(c.Rides))
204
 		fmt.Fprintf(output, "%d", len(c.Rides))
199
 		for _, ri := range c.Rides {
205
 		for _, ri := range c.Rides {
200
 			fmt.Fprintf(output, " %d", ri)
206
 			fmt.Fprintf(output, " %d", ri)
201
 		}
207
 		}
202
 		fmt.Fprintf(output, "\n")
208
 		fmt.Fprintf(output, "\n")
209
+		totalScore += c.score
203
 	}
210
 	}
211
+	fmt.Printf("%d\n", totalScore)
204
 }
212
 }
205
 
213
 
206
 func main() {
214
 func main() {