Skip to content

Commit

Permalink
Merge pull request #51 from Longwater1234/dev
Browse files Browse the repository at this point in the history
fixed #44
  • Loading branch information
Longwater1234 authored Jan 23, 2025
2 parents 3d65760 + 6b2816a commit 5df1203
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
32 changes: 16 additions & 16 deletions room/enemy_detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions room/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down

0 comments on commit 5df1203

Please sign in to comment.