diff --git a/room/enemy_detect.go b/room/enemy_detect.go index 7744447..b27fd05 100644 --- a/room/enemy_detect.go +++ b/room/enemy_detect.go @@ -45,14 +45,14 @@ func collectFrontLHS(p *player.Player, cellIdx int32, gameMap map[int32]*game.Pi // do swap deltaForward, deltaBehindEnemy = deltaBehindEnemy, deltaForward } - var mSign int32 = +1 // direction. up +1, down -1 + var direction int32 = +1 // up +1, down -1 // if player piece is Black (PLAYER 2), swap values if p.Name == game.TeamColor_TEAM_BLACK.String() { - mSign = -1 + direction = -1 deltaBehindEnemy, deltaForward = deltaForward, deltaBehindEnemy } - var cellAheadIdx int32 = cellIdx + (deltaForward * mSign) + var cellAheadIdx int32 = cellIdx + (deltaForward * direction) if cellAheadIdx > 32 || cellAheadIdx < 1 { return false } @@ -63,7 +63,7 @@ func collectFrontLHS(p *player.Player, cellIdx int32, gameMap map[int32]*game.Pi return false } - cellBehindEnemy := cellIdx + (deltaBehindEnemy * mSign) + (deltaForward * mSign) // south-east (of enemy) + cellBehindEnemy := cellIdx + (deltaBehindEnemy * direction) + (deltaForward * direction) // south-east (of enemy) if cellBehindEnemy > 32 || cellBehindEnemy < 1 { return false } @@ -92,14 +92,14 @@ func collectFrontRHS(p *player.Player, cellIdx int32, gameMap map[int32]*game.Pi //do swap deltaBehindEnemy, deltaForward = deltaForward, deltaBehindEnemy } - var mSign int32 = +1 // direction. up +1, down -1 + var direction int32 = +1 // up +1, down -1 // if piece is Black (PLAYER 2), swap values if p.Name == game.TeamColor_TEAM_BLACK.String() { - mSign = -1 + direction = -1 deltaBehindEnemy, deltaForward = deltaForward, deltaBehindEnemy } - var cellAheadIdx int32 = cellIdx + (deltaForward * mSign) + var cellAheadIdx int32 = cellIdx + (deltaForward * direction) if cellAheadIdx > 32 || cellAheadIdx < 1 { return false } @@ -110,7 +110,7 @@ func collectFrontRHS(p *player.Player, cellIdx int32, gameMap map[int32]*game.Pi return false } - cellBehindEnemy := cellIdx + (deltaBehindEnemy * mSign) + (deltaForward * mSign) // south-west (of enemy) + cellBehindEnemy := cellIdx + (deltaBehindEnemy * direction) + (deltaForward * direction) // south-west (of enemy) if cellBehindEnemy > 32 || cellBehindEnemy < 1 { return false } @@ -138,14 +138,14 @@ func collectBehindRHS(king *player.Player, cellIdx int32, gameMap map[int32]*gam if game.IsEvenCellRow(cellIdx) { deltaForward, deltaBehindEnemy = deltaBehindEnemy, deltaForward } - var mSign int32 = +1 // direction + var direction int32 = +1 // for King it's reversed // if player piece is Black (PLAYER 2), swap values if king.Name == game.TeamColor_TEAM_BLACK.String() { - mSign = -1 + direction = -1 deltaForward, deltaBehindEnemy = deltaBehindEnemy, deltaForward } - var cellAheadIdx int32 = cellIdx - (deltaForward * mSign) + var cellAheadIdx int32 = cellIdx - (deltaForward * direction) if cellAheadIdx > 32 || cellAheadIdx < 1 { return false } @@ -156,7 +156,7 @@ func collectBehindRHS(king *player.Player, cellIdx int32, gameMap map[int32]*gam return false } - cellBehindEnemy := cellIdx - (deltaBehindEnemy * mSign) - (deltaForward * mSign) // south-east (of enemy) + cellBehindEnemy := cellIdx - (deltaBehindEnemy * direction) - (deltaForward * direction) // south-east (of enemy) if cellBehindEnemy > 32 || cellBehindEnemy < 1 { return false } @@ -184,14 +184,14 @@ func collectBehindLHS(king *player.Player, cellIdx int32, gameMap map[int32]*gam if game.IsEvenCellRow(cellIdx) { deltaForward, deltaBehindEnemy = deltaBehindEnemy, deltaForward } - var mSign int32 = +1 // direction. +1 forward, -1 back + var direction int32 = +1 // for King it's reversed // if player piece is Black (PLAYER 2), do swap if king.Name == game.TeamColor_TEAM_BLACK.String() { - mSign = -1 + direction = -1 deltaForward, deltaBehindEnemy = deltaBehindEnemy, deltaForward } - var cellAheadIdx int32 = cellIdx - (deltaForward * mSign) + var cellAheadIdx int32 = cellIdx - (deltaForward * direction) if cellAheadIdx > 32 || cellAheadIdx < 1 { return false } @@ -202,7 +202,7 @@ func collectBehindLHS(king *player.Player, cellIdx int32, gameMap map[int32]*gam return false } - cellBehindEnemy := cellIdx - (deltaBehindEnemy * mSign) - (deltaForward * mSign) // south-west of enemy + cellBehindEnemy := cellIdx - (deltaBehindEnemy * direction) - (deltaForward * direction) // south-west of enemy if cellBehindEnemy > 32 || cellBehindEnemy < 1 { return false } diff --git a/room/generator.go b/room/generator.go index 3633bcc..fbf86fe 100644 --- a/room/generator.go +++ b/room/generator.go @@ -58,8 +58,7 @@ func generateGameMap(p1 *player.Player, p2 *player.Player) map[int32]*game.Piece return gameMap } -// generatePieces using secure RNG for the two players. If an error occurs, -// it sends a signal to the `gameOver` channel and panics. +// generatePieces using secure RNG for the two players. If error occurs, send signal via gameOver channel func generatePieces(p1 *player.Player, p2 *player.Player, gameOver chan<- bool) { bigMax := big.NewInt(int64(upperLimit)) for i := 0; i < len(p1.Pieces); i++ {