add an all-in-one script for running tests; format and fix some code; add ci.yml
This commit is contained in:
@@ -458,12 +458,12 @@ func (m *Manager) PlaceShips(ctx context.Context, match *Match, slotIdx int, shi
|
||||
// If the player does not have the right of turn, the message is ignored and ErrNotYourTurn is returned.
|
||||
// If the position is out of bounds or already struck, FireResultInvalidPosition is sent to the shooter.
|
||||
// Otherwise:
|
||||
// - Miss: marks cell as struck, sends FireResultMiss to shooter, turn passes to opponent.
|
||||
// - Hit: marks cell as struck, sends FireResultHit to shooter, turn does not pass.
|
||||
// - Sunk: marks ship and all surrounding cells (including diagonals) as struck, sends FireResultSunk to shooter.
|
||||
// If all opponent ships are destroyed, match finishes: END messages (victory/defeat) are sent to both players,
|
||||
// and connections are closed immediately.
|
||||
// Otherwise, turn does not pass.
|
||||
// - Miss: marks cell as struck, sends FireResultMiss to shooter, turn passes to opponent.
|
||||
// - Hit: marks cell as struck, sends FireResultHit to shooter, turn does not pass.
|
||||
// - Sunk: marks ship and all surrounding cells (including diagonals) as struck, sends FireResultSunk to shooter.
|
||||
// If all opponent ships are destroyed, match finishes: END messages (victory/defeat) are sent to both players,
|
||||
// and connections are closed immediately.
|
||||
// Otherwise, turn does not pass.
|
||||
func (m *Manager) Fire(ctx context.Context, match *Match, slotIdx int, x, y int) (int, error) {
|
||||
res, won, matchID, err := m.fireLocked(ctx, match, slotIdx, x, y)
|
||||
if won {
|
||||
|
||||
@@ -199,10 +199,10 @@ func ParsePlaceShips(args []json.RawMessage) ([]Ship, error) {
|
||||
}
|
||||
|
||||
// ValidateShips validates the ship placement on the 10x10 board:
|
||||
// - exactly 10 ships with sizes [1, 1, 1, 1, 2, 2, 2, 3, 3, 4]
|
||||
// - all ship cells are within bounds (0 <= x < 10, 0 <= y < 10)
|
||||
// - no ships overlap or touch each other in any direction (including diagonals),
|
||||
// ensuring a gap of at least 1 cell between any two ships.
|
||||
// - exactly 10 ships with sizes [1, 1, 1, 1, 2, 2, 2, 3, 3, 4]
|
||||
// - all ship cells are within bounds (0 <= x < 10, 0 <= y < 10)
|
||||
// - no ships overlap or touch each other in any direction (including diagonals),
|
||||
// ensuring a gap of at least 1 cell between any two ships.
|
||||
func ValidateShips(ships []Ship) error {
|
||||
if len(ships) != ShipCount {
|
||||
return fmt.Errorf("expected %d ships, got %d", ShipCount, len(ships))
|
||||
@@ -327,4 +327,3 @@ func ParseFireResult(args []json.RawMessage) (seq int64, result int, err error)
|
||||
func BuildFireResult(seq int64, result int) []byte {
|
||||
return build([]any{OpFireResult, seq, result})
|
||||
}
|
||||
|
||||
|
||||
@@ -348,4 +348,3 @@ func TestParseFireResultErrors(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -198,10 +198,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if unverified != nil {
|
||||
if existing := h.Manager.GetMatch(unverified.MatchID); existing != nil && existing.GameToken() == gameToken {
|
||||
gc = &auth.GameClaims{
|
||||
MatchID: existing.ID,
|
||||
Player1ID: existing.PlayerIDs()[0],
|
||||
Player2ID: existing.PlayerIDs()[1],
|
||||
RawToken: gameToken,
|
||||
MatchID: existing.ID,
|
||||
Player1ID: existing.PlayerIDs()[0],
|
||||
Player2ID: existing.PlayerIDs()[1],
|
||||
RawToken: gameToken,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -584,5 +584,3 @@ func TestFireWinOverWebSocket(t *testing.T) {
|
||||
t.Fatalf("late join want END victory, got %v", lateEnd)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user