[plt-scheme] multi-dimensional arrays

From: Iain Gray (iain.gray at ednet.co.uk)
Date: Sun Dec 8 05:58:14 EST 2002

I am attempting to set up a two dimensional array to represent a Hex 
game board (11 by 11 hexagons).

My definitions are:-

(define board (make-vector 11 (make-vector 11 'empty)))

(define (board-set! row col piece)
   (vector-set! board row
                (vector-set! (vector-ref board row) col piece)))

with corresponding interactions:-

Welcome to DrScheme, version 202.
Language: Textual (MzScheme, includes R5RS).
 > board
#11(#0=#11(empty))
 > (board-set! 5 5 'black)
 > board
#11(#0=#11(empty empty empty empty empty black empty) #0# #0# #0# #0# 
#<void> #0#)
 >

My problem is getting a single piece ('black or 'white) written to the 
board, rather than multiple copies.

I hope I have not missed something obvious!

Regards,

Iain Gray



Posted on the users mailing list.