#lang racket

;;; multi-dimensional arrays
(require srfi/25)

(define-syntax-rule
  (call-with-hash function hash keys ...)
  (function (car (hash-ref hash 'keys)) ...))

(define (end-turn port)
  (displayln "go" port)
  (flush-output port) )

(define (main)
  (define setup-data (parse-turn-data (read-turn-data "ready" (current-input-port))))
  (define bot
    (call-with-hash create-bot setup-data
                    turntime
                    rows cols
                    turns
                    viewradius2 attackradius2 spawnradius2
                    player_seed))
  (displayln setup-data (current-error-port))
  (end-turn (current-output-port))
  (let loop ()
    (let ((data (parse-turn-data (read-turn-data "go" (current-input-port)))))
      (if (hash-has-key? data 'end)
          (begin (end-turn (current-output-port))
                 (displayln data (current-error-port)))
          (begin (end-turn (current-output-port))
                 (displayln data (current-error-port))
                 (loop)))))
  )

(define (read-turn-data end-string port)
  (let loop ((ret '()))
    (let ((line (read-line port)))
      (if (string=? line end-string)
          ret
          (loop (cons line ret))))))

(define (parse-turn-data data)
  (make-immutable-hash
   (map (lambda (datum)
          (let ((split-datum (regexp-split " +" datum)))
            (cons (string->symbol (car split-datum)) (map string->number (cdr split-datum)))))
        data)))

(define (create-bot turntime rows cols turns viewradius2 attackradius2 spawnradius2 player_seed)
  (define terrain (make-array (shape 0 rows 0 cols)))
  #t
)  

(main)