Skip to content

Instantly share code, notes, and snippets.

Last active Mar 20, 2016
What would you like to do?
package main
import (
type Message struct {
// The GameID is used internally to reference games, and once the game is complete, you can view the results of the game at https://localhost/#/games/:id
GameID string
// Once the game is complete an extra message is sent down with a GameOverStatus > 0. 1=WhiteWin, 2=BlackWin, 3=Stalemate
GameOverStatus int //white win, black win, stalemate
// A list of 8 strings that layout the visible board. Print this out, and it'll all make sense. Lowercase characters are white, uppercase are black.
// k = king
// q = queen
// n = knight
// b = bishop
// r = rook
// p = pawn
Board []string
// Lets you know what color you are, for all the challenges you are white
IsWhite bool
type Response struct {
To string
From string
func main() {
dialer := websocket.Dialer{}
headers := make(http.Header)
// You can get this from the profile page
token := "xxxx-xxxx-xxxx-xxxx"
headers.Add("X-Websocket-Token", token)
// You can the challenges from the profile page
conn, _, err := dialer.Dial("wss://localhost:8080/battle/thecrazyking", headers)
if err != nil {
fmt.Println("[+] Connected!")
for {
var message Message
err = conn.ReadJSON(&message)
if err != nil {
if message.GameOverStatus > 0 {
fmt.Println("[+] Game Over!")
response, _ := MakeMove(message)
err := conn.WriteJSON(response)
if err != nil {
func MakeMove(message Message) Response {
// Here goes your logic!
// You need to return your next move in Chess Algebraic notation
// For example to move the pawn in front of the king you would return
// Response{From: "e3", To: "e4"}
func PrintBoard(message Message) Response {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment