나는 Scheme에서 간단한 체스 프로그램을 작업 해왔고, 내가 정의한 도우미 함수 중 하나가 조각과 좌표 (current-location)를 소비하고 체스 보드에서 지정된 좌표 (move-here)를 사용하여 Move-here 좌표에있는 조각을 전환합니다. 이 기능은 내가 원하는 바대로 작동했지만, 이제는 더 이상 제대로 작동하지 않습니다. 나는 이것이 무엇을 일으킬 수 있는지 전혀 모르고 있으며, 버그를 찾으려고 잠시 동안 코드를 추적하고 추적하고있다. 나는 누군가가 상황을 밝힐 수 있기를 희망하고있다. 여기 Scheme : 체스를위한 배열에서 요소를 돌연변이
코드 내에서 사용되는 구조와 함께, 부분 스위칭 기능에 대한 코드는 다음(define-struct place (row column piece))
;; Place is a structure (make-place r c p) where r is the rank of a piece
;; which is a symbol of 'Pawn, 'Rook, 'Knight, 'Bishop, 'King or 'Queen
;; and column and place. Together c and p give the placement coordinates,
;; where column is one symbol from '(a b c d e f g h) and row is a number from
;; 1 - 8 inclusive.
(define-struct piece (rank color))
;; Piece is a structure (make-piece r col) where rank is as described for a place structure,
;; and colour is a symbo either 'black or 'white.
(define move-counter 1) ; Keeps track of the current number of mves made.
;; Odd indicates white to move, else black to move.
;; Swap-in: '(Symbol Symbol Nat) '(Symbol Nat) -> '(-2- void)
;; Conditions:
;; Pre: Swap-in is '(rank column row) From is '(column row)
;; Post: produces list of lists containing -2- and void. where void represents
;; any changed values.
;; Purpose: Swap-piece is a helper for any X-Move function that dictates the legal
;; moves of a given piece.
(define (swap-piece swap-in from)
(map (λ (x)
(map (λ (piece)
(cond
[(and (= (third swap-in) (place-row piece))
(symbol=? (second swap-in) (place-column piece)))
(set-place-piece! piece
(make-piece (first swap-in) (cond
[(odd? move-counter) 'white]
[else 'black])))]
[(and (= (second from) (place-row piece))
(symbol=? (first from) (place-column piece)))
(set-place-piece! piece (make-piece empty empty))]
[else void]))
x))
board))
여기 두 가지 예이다; 첫 번째 출력은 무엇이며, 두 번째 출력은 입니다 (예에서 스왑 조각에 작은 수정이있어서 그 매개 변수 중 하나가 보드이므로 전체 배열을 사용하지 않습니다. 내 체스 보드를 가지고).
> Example-board
(list
(list
(make-place 8 'a (make-piece 'Rook 'black))
(make-place 7 'a (make-piece empty empty)))
(list
(make-place 4 'a (make-piece 'Queen 'white))
(make-place 6 'b (make-piece 'King 'White))))
그러나, 나는 기대 출력은 다음과 같습니다 :
> Example-board
(list
(list
(make-place 8 'a (make-piece 'Rook 'black))
(make-place 7 'a (make-piece 'Queen 'white)))
(list
(make-place 4 'a (make-piece empty empty))
(make-place 6 'b (make-piece 'King 'White))))
죄송합니다, 긴 게시물에 대한,하지만 난 그냥
(define Example-board (list
(list
(make-place 8 'a (make-piece 'Rook 'black))
(make-place 7 'a (make-piece 'Pawn 'black)))
(list
(make-place 4 'a (make-piece 'Queen 'white))
(make-place 6 'b (make-piece 'King 'White)))))
> (swap-piece '(Queen a 4) '(a 7) Example-board)
(shared ((-2- void)) (list (list -2- (void)) (list (void) -2-)))
은 그래서 예 보드가 업데이트 된 보드를 얻기 위해 전화 이것이 일어나는 원인을 파악할 수 없습니다. 앞에서 말했듯이이 코드는 불과 몇 시간 전만해도 작동한다고 확신합니다.
편집 :지도 기능이 작동하는 목록 인 보드를 스왑 피스 기능이 체스 판이라고 추가해야합니다.
가능한 중복 (http://stackoverflow.com/questions/21592853/scheme-function-that-stopped-working) – msandiford
사실, 이것은 마이그레이션 된 x- 게시물입니다. – jozefg
@jozefg 예, 그렇습니다. 나는 프로그래머들에게도 그것을 게시했다. 그것이 어디 있어야하는지 몰랐다. – Plopperzz