Add missing ruleset params to request body and --debug-requests option (#55)
* fix sending of new params * add royale and squad settings to requests * add --debug-requests option * update test for request body and add helper Co-authored-by: Penelope Phippen <penelope@hey.com>
This commit is contained in:
parent
0cba5eff59
commit
31faba642c
5 changed files with 179 additions and 10 deletions
|
|
@ -54,9 +54,29 @@ type BoardResponse struct {
|
|||
Snakes []SnakeResponse `json:"snakes"`
|
||||
}
|
||||
|
||||
type GameResponseRulesetSettings struct {
|
||||
HazardDamagePerTurn int32 `json:"hazardDamagePerTurn"`
|
||||
FoodSpawnChance int32 `json:"foodSpawnChance"`
|
||||
MinimumFood int32 `json:"minimumFood"`
|
||||
RoyaleSettings RoyaleSettings `json:"royale"`
|
||||
SquadSettings SquadSettings `json:"squad"`
|
||||
}
|
||||
|
||||
type RoyaleSettings struct {
|
||||
ShrinkEveryNTurns int32 `json:"shrinkEveryNTurns"`
|
||||
}
|
||||
|
||||
type SquadSettings struct {
|
||||
AllowBodyCollisions bool `json:"allowBodyCollisions"`
|
||||
SharedElimination bool `json:"sharedElimination"`
|
||||
SharedHealth bool `json:"sharedHealth"`
|
||||
SharedLength bool `json:"sharedLength"`
|
||||
}
|
||||
|
||||
type GameResponseRuleset struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Settings GameResponseRulesetSettings `json:"settings"`
|
||||
}
|
||||
|
||||
type GameResponse struct {
|
||||
|
|
@ -101,6 +121,7 @@ var GameType string
|
|||
var ViewMap bool
|
||||
var Seed int64
|
||||
var TurnDelay int32
|
||||
var DebugRequests bool
|
||||
|
||||
var FoodSpawnChance int32
|
||||
var MinimumFood int32
|
||||
|
|
@ -128,6 +149,7 @@ func init() {
|
|||
playCmd.Flags().BoolVarP(&ViewMap, "viewmap", "v", false, "View the Map Each Turn")
|
||||
playCmd.Flags().Int64VarP(&Seed, "seed", "r", time.Now().UTC().UnixNano(), "Random Seed")
|
||||
playCmd.Flags().Int32VarP(&TurnDelay, "delay", "d", 0, "Turn Delay in Milliseconds")
|
||||
playCmd.Flags().BoolVar(&DebugRequests, "debug-requests", false, "Log body of all requests sent")
|
||||
|
||||
playCmd.Flags().Int32Var(&FoodSpawnChance, "foodSpawnChance", 15, "Percentage chance of spawning a new food every round")
|
||||
playCmd.Flags().Int32Var(&MinimumFood, "minimumFood", 1, "Minimum food to keep on the board every turn")
|
||||
|
|
@ -263,6 +285,9 @@ func initializeBoardFromArgs(ruleset rules.Ruleset, snakes []Battlesnake) *rules
|
|||
requestBody := getIndividualBoardStateForSnake(state, snake, ruleset)
|
||||
u, _ := url.ParseRequestURI(snake.URL)
|
||||
u.Path = path.Join(u.Path, "start")
|
||||
if DebugRequests {
|
||||
log.Printf("POST %s: %v", u, string(requestBody))
|
||||
}
|
||||
_, err = HttpClient.Post(u.String(), "application/json", bytes.NewBuffer(requestBody))
|
||||
if err != nil {
|
||||
log.Printf("[WARN]: Request to %v failed", u.String())
|
||||
|
|
@ -326,6 +351,9 @@ func getMoveForSnake(ruleset rules.Ruleset, state *rules.BoardState, snake Battl
|
|||
requestBody := getIndividualBoardStateForSnake(state, snake, ruleset)
|
||||
u, _ := url.ParseRequestURI(snake.URL)
|
||||
u.Path = path.Join(u.Path, "move")
|
||||
if DebugRequests {
|
||||
log.Printf("POST %s: %v", u, string(requestBody))
|
||||
}
|
||||
res, err := HttpClient.Post(u.String(), "application/json", bytes.NewBuffer(requestBody))
|
||||
move := snake.LastMove
|
||||
if err != nil {
|
||||
|
|
@ -353,6 +381,9 @@ func sendEndRequest(ruleset rules.Ruleset, state *rules.BoardState, snake Battle
|
|||
requestBody := getIndividualBoardStateForSnake(state, snake, ruleset)
|
||||
u, _ := url.ParseRequestURI(snake.URL)
|
||||
u.Path = path.Join(u.Path, "end")
|
||||
if DebugRequests {
|
||||
log.Printf("POST %s: %v", u, string(requestBody))
|
||||
}
|
||||
_, err := HttpClient.Post(u.String(), "application/json", bytes.NewBuffer(requestBody))
|
||||
if err != nil {
|
||||
log.Printf("[WARN]: Request to %v failed", u.String())
|
||||
|
|
@ -371,6 +402,20 @@ func getIndividualBoardStateForSnake(state *rules.BoardState, snake Battlesnake,
|
|||
Game: GameResponse{Id: GameId, Timeout: Timeout, Ruleset: GameResponseRuleset{
|
||||
Name: ruleset.Name(),
|
||||
Version: "cli", // TODO: Use GitHub Release Version
|
||||
Settings: GameResponseRulesetSettings{
|
||||
HazardDamagePerTurn: HazardDamagePerTurn,
|
||||
FoodSpawnChance: FoodSpawnChance,
|
||||
MinimumFood: MinimumFood,
|
||||
RoyaleSettings: RoyaleSettings{
|
||||
ShrinkEveryNTurns: ShrinkEveryNTurns,
|
||||
},
|
||||
SquadSettings: SquadSettings{
|
||||
AllowBodyCollisions: true,
|
||||
SharedElimination: true,
|
||||
SharedHealth: true,
|
||||
SharedLength: true,
|
||||
},
|
||||
},
|
||||
}},
|
||||
Turn: Turn,
|
||||
Board: BoardResponse{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue