about summary refs log tree commit diff stats
path: root/chessboard.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-12-27 23:30:43 -0800
committerKartik K. Agaram <vc@akkartik.com>2017-12-27 23:30:43 -0800
commitf94f03cfb01011f0b0416cb624842b86ad1b1666 (patch)
treee8bea52441f62a13017b138b6707cf1ee0b003c6 /chessboard.mu
parent3cb4e19e354dcda82db07275555ef7872f1c5ba4 (diff)
downloadmu-f94f03cfb01011f0b0416cb624842b86ad1b1666.tar.gz
4167 - show square colors in chessboard app
Diffstat (limited to 'chessboard.mu')
-rw-r--r--chessboard.mu12
1 files changed, 11 insertions, 1 deletions
diff --git a/chessboard.mu b/chessboard.mu
index 946708e1..3797c805 100644
--- a/chessboard.mu
+++ b/chessboard.mu
@@ -161,7 +161,8 @@ def print screen:&:screen, board:board -> screen:&:screen [
       break-if done?
       f:&:@:char <- index *board, col
       c:char <- index *f, row
-      print screen, c
+      bg:num <- square-color row, col
+      print screen, c, 7/white, bg
       print screen, space
       col <- add col, 1
       loop
@@ -177,6 +178,15 @@ def print screen:&:screen, board:board -> screen:&:screen [
   cursor-to-next-line screen
 ]
 
+def square-color row:num, col:num -> result:num [
+  local-scope
+  load-inputs
+  result <- copy 0/black
+  x:num <- add row, col
+  _, rem:num <- divide-with-remainder x, 2
+  return-if rem, 238
+]
+
 def initial-position -> board:board [
   local-scope
   # layout in memory (in raster order):