diff --git a/game.go b/game.go index 259ed3c..a2a4144 100644 --- a/game.go +++ b/game.go @@ -148,13 +148,13 @@ func (game *Game) calculateState() { } for _, w := range winner { - if isSubArray(w[:], game.aiFields) { + if len(game.aiFields) >= 3 && isSubArray(w[:], game.aiFields) { game.state = GameStateAIWon game.winnerFields = w game.winner = WinnerAI return } - if isSubArray(w[:], game.userFields) { + if len(game.userFields) >= 3 && isSubArray(w[:], game.userFields) { game.state = GameStateAILost game.winnerFields = w game.winner = WinnerUser diff --git a/main.go b/main.go index de992aa..e5277e4 100644 --- a/main.go +++ b/main.go @@ -27,31 +27,12 @@ func main() { r.GET("/", func(c *gin.Context) { lang := getLang(c) - fmt.Println(lang) - c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/%s/0/%s", lang, initGame(false))) + c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/%s/0/x", lang)) }) r.GET("/:lang", func(c *gin.Context) { lang := getLang(c) - c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/%s/0/%s", lang, initGame(false))) - }) - - r.GET("/:lang/:ai_second", func(c *gin.Context) { - lang := getLang(c) - aiSecond, err := strconv.ParseBool(c.Param("ai_second")) - if err != nil { - aiSecond = false - } - - aiSecondVar := "0" - if aiSecond { - aiSecondVar = "1" - } - - c.Redirect( - http.StatusMovedPermanently, - fmt.Sprintf("/%s/%s/%s", lang, aiSecondVar, initGame(aiSecond)), - ) + c.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/%s/0/x", lang)) }) r.GET("/:lang/:ai_second/:game", func(c *gin.Context) { @@ -65,7 +46,6 @@ func main() { game := newGame(gameFlow, aiSecond) - fmt.Println(gameState) if gameState == GameStateInProgress && !game.isFinished() { gameFlow = gameFlow + getNewClick(gameFlow) game = newGame(gameFlow, aiSecond) @@ -105,15 +85,6 @@ func main() { r.Run() } -func initGame(aiSecond bool) string { - if aiSecond { - return "0" - } - - // get from DB - return "1" -} - func getLang(c *gin.Context) string { session := sessions.Default(c) @@ -140,6 +111,10 @@ func getGameFlow(c *gin.Context) (string, int) { return gameFlow, GameStateWaitingUser } + if "x" == gameFlow { + return "", GameStateInProgress + } + if "0" == string(gameFlow[0]) { gameFlow = string(gameFlow[1:]) } diff --git a/views/title.en.html b/views/title.en.html index 4401c56..61a87cb 100644 --- a/views/title.en.html +++ b/views/title.en.html @@ -10,5 +10,6 @@
diff --git a/views/title.sgs.html b/views/title.sgs.html index cdbb6bc..23fec07 100644 --- a/views/title.sgs.html +++ b/views/title.sgs.html @@ -10,4 +10,5 @@