
あのあと色々と試したんだけど・・タイルサイズが100だと大きすぎて駄目、UI部分を考えると80ピクセル四方で4x4が限界かなぁ・・

続きましてグラフィック関連では毎度面倒な座標チェック。バックを青にして"left"で"top"にすると座標が左上を中心にできる様子で計算しやすいと判断。「道路」部分は横で60x10、縦で10x60にするといい感じ。座標はそのまま縦横+80していけば良いな

集落(スクエアの交点に設置)はこういう設定でいい感じの位置になると。これも縦横80足せば次のパネルに設置できる。
まあ、ここまでは下ごしらえみたいなもんで・・・問題はどういうデータ構造にしたら集落(交点)とか道路(四辺)の座標を管理できるか、だな!
最初、パネル1枚を構造体にしてフィールドに4つの頂点と辺を記録させて・・と思ってたんだけど、頂点じゃなくて交点(隣のスクエアと共用)だし、辺も共用されてるじゃないか(-_-;)

バイト中にモップをかけながら考えたんだけど・・泥臭いけど左上から数えてリストにして管理する事しか思いつかんかった。交点(四隅の頂点)は全部で25、辺は横が4x5、縦が5x4で40。これらを#fで埋めて#tの値でどのプレイヤーの何が置かれるのかを記録すると。

法則を見つけるために実際に数値を入れていく。初期場所のテストオッケイ

X方向に動かす場合オッケイ

Y方向に動かす場合オッケイ
じゃあ実際にはどういう風にリストからマップに反映させるか・・欲しいデータは#tの場合に数値と、その#tがリストの何番目にあるのか?ですよね。
厄介な辺の場合から考えてみる。最上辺は1-4、次に左上の赤パネルの左辺が5、右辺が6・・・と言う感じで横は4増えて、縦は5増える・・ってルールなんだけど。Counterをつけて再帰で回して場合分けするしか思いつかなかったので

こういうカッコ悪い補助関数を書いて(数式だけで判定するのが思いつかなかった(-_-;)

多重Caseで縦横の場合の道路グラフィックをリスト出力
続いては座標なんだけど・・これも縦横の場合で分けないといけないので・・

このような腰の抜けそうな補助関数を書きまして!

それらを使った座標リストを出す部分を書きまして

*roads-p*に適当に1と2を入れまして

ハイどうだ!道路表示部分の根っこはコレでいい感じじゃないかな?交点&四隅の集落の表示もほぼコピペで作れるし、データの管理はリストで行うと決まったので、後はなんとかなりそうな気がする。
というところで本日はここまで~ いや~やっぱりデータ以外の部分を作るのは楽しい(^_^;)
以下、本日のコードです
#lang racket
(require 2htdp/universe 2htdp/image lang/posn)
(require srfi/1)
(require srfi/13)
(require racket/struct)
(require racket/match)
(struct WORLD (PLAYERS MAP PHASE TURN))
(struct PLAYER (NAME COLOR CARDS ROAD VILLAGE TOWN))
(struct CARD (WOOD IRON SHEEP BLOCK))
(define *map-zero* '(
(1 2 3 4)
(2 3 4 1)
(3 4 1 2)
(4 1 2 3)
))
(define *cross-p* '(#f #f #f #f #f #f #f #f #f 1 #f #f #f #f #f #f 2 #f #f #f #f #f #f #f #f)) ;25
(define *roads-p* '(1 1 #f #f #f #f #f #f 1 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 2
#f #f #f #f #f 2 #f #f #f #f #f #f #f #f 1)) ;40
(define (x40 x y)
(make-posn (+ (* x 40) (* (- x 1) 40))
(+ (* y 40) (* (- y 1) 40))))
(define (place-map)
(place-images/align
(map (lambda (x) (square 80 "solid"
(case x
((1) "red")
((2) "white")
((3) "green")
((4) "yellow")
(else "blue")))) (flatten *map-zero*))
(flatten (for/list ((i (iota 4 1 1)))
(for/list ((j (iota 4 1 1)))
(x40 i j)))) "left" "top"
(rectangle 400 400 "solid" "blue")))
(define (place-town)
(place-images/align
(list
;(text "●" 30 "olive")
)
(list
;(make-posn 32 28)
)
"left" "top" (place-map)))
(define (tate&yoko x)
(cond ((<= x 4) 'yoko)
((and (>= x 5) (<= x 9)) 'tate)
((and (>= x 10) (<= x 13)) 'yoko)
((and (>= x 14) (<= x 18)) 'tate)
((and (>= x 19) (<= x 22)) 'yoko)
((and (>= x 23) (<= x 27)) 'tate)
((and (>= x 28) (<= x 31)) 'yoko)
((and (>= x 32) (<= x 36)) 'tate)
(else 'yoko)))
(define (tate&yokoX x)
(cond ((<= x 4) (+ 50 (* 80 (- x 1))))
((and (>= x 5) (<= x 9)) (+ 34 (* 80 (- x 5))))
((and (>= x 10) (<= x 13)) (+ 50 (* 80 (- x 10))))
((and (>= x 14) (<= x 18)) (+ 34 (* 80 (- x 14))))
((and (>= x 19) (<= x 22)) (+ 50 (* 80 (- x 19))))
((and (>= x 23) (<= x 27)) (+ 34 (* 80 (- x 23))))
((and (>= x 28) (<= x 31)) (+ 50 (* 80 (- x 28))))
((and (>= x 32) (<= x 36)) (+ 34 (* 80 (- x 32))))
(else (+ 50 (* 80 (- x 37))))))
(define (tate&yokoY x)
(cond ((<= x 4) 36)
((and (>= x 5) (<= x 9)) 50)
((and (>= x 10) (<= x 13)) 116)
((and (>= x 14) (<= x 18)) 130)
((and (>= x 19) (<= x 22)) 196)
((and (>= x 23) (<= x 27)) 210)
((and (>= x 28) (<= x 31)) 276)
((and (>= x 32) (<= x 36)) 290)
(else 356)))
(define (place-road)
(place-images/align
(let loop ((lst *roads-p*) (count 1) (acc '()))
(if (null? lst)
(reverse acc)
(loop (cdr lst) (+ count 1) (if (car lst) (cons (case (tate&yoko count)
((yoko) (rectangle 60 10 "solid" (case (car lst)
((1) "black")
((2) "blue"))))
((tate) (rectangle 10 60 "solid" (case (car lst)
((1) "black")
((2) "blue"))))) acc)
acc))))
(let loopB ((lst *roads-p*) (count 1) (acc '()))
(if (null? lst)
(reverse acc)
(loopB (cdr lst) (+ count 1)
(if (car lst)
(cons (make-posn (tate&yokoX count) (tate&yokoY count)) acc)
acc))))
; (
; (rectangle 60 10 "solid" "black")
; (rectangle 60 10 "solid" "black")
; (rectangle 60 10 "solid" "black")
; (rectangle 10 60 "solid" "white")
; (rectangle 10 60 "solid" "blue")
; (rectangle 10 60 "solid" "blue")
; )
; (list
; (make-posn 30 30)
; (make-posn 50 36)
; (make-posn 130 36)
; (make-posn 50 116)
; (make-posn 34 50)
; (make-posn 114 50)
; (make-posn 114 130)
; )
"left" "top" (place-town)))
(place-road)
(require 2htdp/universe 2htdp/image lang/posn)
(require srfi/1)
(require srfi/13)
(require racket/struct)
(require racket/match)
(struct WORLD (PLAYERS MAP PHASE TURN))
(struct PLAYER (NAME COLOR CARDS ROAD VILLAGE TOWN))
(struct CARD (WOOD IRON SHEEP BLOCK))
(define *map-zero* '(
(1 2 3 4)
(2 3 4 1)
(3 4 1 2)
(4 1 2 3)
))
(define *cross-p* '(#f #f #f #f #f #f #f #f #f 1 #f #f #f #f #f #f 2 #f #f #f #f #f #f #f #f)) ;25
(define *roads-p* '(1 1 #f #f #f #f #f #f 1 #f #f #f #f #f #f #f #f #f #f #f #f #f #f #f 2
#f #f #f #f #f 2 #f #f #f #f #f #f #f #f 1)) ;40
(define (x40 x y)
(make-posn (+ (* x 40) (* (- x 1) 40))
(+ (* y 40) (* (- y 1) 40))))
(define (place-map)
(place-images/align
(map (lambda (x) (square 80 "solid"
(case x
((1) "red")
((2) "white")
((3) "green")
((4) "yellow")
(else "blue")))) (flatten *map-zero*))
(flatten (for/list ((i (iota 4 1 1)))
(for/list ((j (iota 4 1 1)))
(x40 i j)))) "left" "top"
(rectangle 400 400 "solid" "blue")))
(define (place-town)
(place-images/align
(list
;(text "●" 30 "olive")
)
(list
;(make-posn 32 28)
)
"left" "top" (place-map)))
(define (tate&yoko x)
(cond ((<= x 4) 'yoko)
((and (>= x 5) (<= x 9)) 'tate)
((and (>= x 10) (<= x 13)) 'yoko)
((and (>= x 14) (<= x 18)) 'tate)
((and (>= x 19) (<= x 22)) 'yoko)
((and (>= x 23) (<= x 27)) 'tate)
((and (>= x 28) (<= x 31)) 'yoko)
((and (>= x 32) (<= x 36)) 'tate)
(else 'yoko)))
(define (tate&yokoX x)
(cond ((<= x 4) (+ 50 (* 80 (- x 1))))
((and (>= x 5) (<= x 9)) (+ 34 (* 80 (- x 5))))
((and (>= x 10) (<= x 13)) (+ 50 (* 80 (- x 10))))
((and (>= x 14) (<= x 18)) (+ 34 (* 80 (- x 14))))
((and (>= x 19) (<= x 22)) (+ 50 (* 80 (- x 19))))
((and (>= x 23) (<= x 27)) (+ 34 (* 80 (- x 23))))
((and (>= x 28) (<= x 31)) (+ 50 (* 80 (- x 28))))
((and (>= x 32) (<= x 36)) (+ 34 (* 80 (- x 32))))
(else (+ 50 (* 80 (- x 37))))))
(define (tate&yokoY x)
(cond ((<= x 4) 36)
((and (>= x 5) (<= x 9)) 50)
((and (>= x 10) (<= x 13)) 116)
((and (>= x 14) (<= x 18)) 130)
((and (>= x 19) (<= x 22)) 196)
((and (>= x 23) (<= x 27)) 210)
((and (>= x 28) (<= x 31)) 276)
((and (>= x 32) (<= x 36)) 290)
(else 356)))
(define (place-road)
(place-images/align
(let loop ((lst *roads-p*) (count 1) (acc '()))
(if (null? lst)
(reverse acc)
(loop (cdr lst) (+ count 1) (if (car lst) (cons (case (tate&yoko count)
((yoko) (rectangle 60 10 "solid" (case (car lst)
((1) "black")
((2) "blue"))))
((tate) (rectangle 10 60 "solid" (case (car lst)
((1) "black")
((2) "blue"))))) acc)
acc))))
(let loopB ((lst *roads-p*) (count 1) (acc '()))
(if (null? lst)
(reverse acc)
(loopB (cdr lst) (+ count 1)
(if (car lst)
(cons (make-posn (tate&yokoX count) (tate&yokoY count)) acc)
acc))))
; (
; (rectangle 60 10 "solid" "black")
; (rectangle 60 10 "solid" "black")
; (rectangle 60 10 "solid" "black")
; (rectangle 10 60 "solid" "white")
; (rectangle 10 60 "solid" "blue")
; (rectangle 10 60 "solid" "blue")
; )
; (list
; (make-posn 30 30)
; (make-posn 50 36)
; (make-posn 130 36)
; (make-posn 50 116)
; (make-posn 34 50)
; (make-posn 114 50)
; (make-posn 114 130)
; )
"left" "top" (place-town)))
(place-road)