This is kind of like tic-tac-toe! The first player has an advantage. Gomoku's swap2 rule makes it fairer and more interesting!
Also a good game to practice writing alpha-beta pruning search (for playing with a computer)! Representing the board as two sets of n^2 bitmaps would speed things up and allow searching more plys (turns) ahead in a given time period. Two because you need to represent black, white, empty states for each square. Sets make it easier/faster to check for "better" placements. I think Marcus is really talking about checking for valid row, column numbers[1]. But this valid row/column index problem can be trivially solved by simply doing a modulo operation! That is, if the user types 45, 45, treat it as if he typed 1, 1 (for a 15x15 board, rows and columns are numbered 0..14). [1] I suspect this is a homework problem..... > On Jan 22, 2019, at 11:37 AM, Michael Jones <[email protected]> wrote: > > I could not decode the question, so I just wrote a program to do it all. > John, does this help? > Change the constants for whatever board geometry and n-in-a-row victory rule > you want. > > https://play.golang.org/p/JtouiOlkGCO <https://play.golang.org/p/JtouiOlkGCO> > > P.S. the progression from 3 to 4 to 5 in a row is a great way to teach kids > important mental skills. > > On Tue, Jan 22, 2019 at 7:39 AM Marcus Low <[email protected] > <mailto:[email protected]>> wrote: > I meant "constant space overhead", sorry. > > On Tuesday, January 22, 2019 at 11:38:02 PM UTC+8, Marcus Low wrote: > As Justin Israel said, you can probably scan them to int and test them as > ints. > > However, if you really need them to be parsed as string, this will help your > runtime, at the cost of constant overhead: > var ( > valueSet = map[string]struct{}{ > "1":nil, > "2":nil, > "3":nil, > .... > "15":nil, > } > ) > > func checkValue(s string) bool { > _, ok := valueSet[s] > return ok > } > > func fix() { > if checkValue(x) { > .... > } > .... > } > > > > On Tuesday, January 22, 2019 at 6:40:52 AM UTC+8, John wrote: > Dear Gophers, > > I have recently made a project of Connect Five. When the imput is wrong it > will have a goroutine problem that says something about out of index, as my > game win function depends on if the x = b and x+1 = b and so on. But if the > imput is not 1,2 1,3 and so on, or it is over 15, 15 it will be wrong. I made > a solution of creating a function like this: > > func fix() { > if x == "1"|| x == "2"|| x == "3"|| x == "4"|| x == "5"|| x == "6"|| x > == "7"|| x == "8"|| x == "9"|| x == "10"|| x == "11"|| x == "12"|| x == > "13"|| x == "14"|| x == "15" { > if y == "1"|| y == "2"|| y == "3"|| y == "4"|| y == "5"|| y == > "6"|| y == "7"|| y == "8"|| y == "9"|| y == "10"|| y == "11"|| y == "12"|| y > == "13"|| y == "14"|| y == "15" { > blwi() > } else { > showBoard() > fmt.Println("Sorry you had entered wrong please enter > again") > fmt.Scanln(&x,&y) > fix() > } > } > > It for some reason won't work. So I wonder if any of you can help me correct > the function and simplify it. (it goes right between the imput and the win > function.) > > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. > > > -- > Michael T. Jones > [email protected] <mailto:[email protected]> > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
