| Author |
Message |
Karl Scherer (Karl)
| | Posted on Thursday, July 18, 2002 - 5:57 am: | |
Contrary to popular belief, it is EASY to test connectivity in Zillions. Example: Two opposite borders of a 9x9 chess board have to be connected. Red owns the left and right borders, Blue the top and bottom ones, the corners are taboo. Each player tries to connect his opposite borders with a fence of dominoes. The dominoes are allowed to only touch at corners in order to be linked as part of the fence. The following shows a simple "Check-win" macro (which only uses flags) for this game. Zone1 is defined as the western border for player Red, but as the northern border for Blue, and so on. ============================================== ;so here is the code to check connectivity: (define Checkwin ;check whether sides are "connected" (corner-touching dominoes O.K.) ; first we flag all friendly pieces that are on the left/top border a0 (while (on-board? x) x (if (and friend? (in-zone? Zone1)) (set-position-flag connected? true)) ) ;now we flag all fence pieces connected to the Zone1 border: (set-flag new-found? true) ;end of the fence not reached yet? (set-flag solved? false) ;borders connected? (while (and (flag? new-found?)(not-flag? solved?)) (set-flag new-found? false) ;initialize flag "new link found" a0 ;scan board (while (and (on-board? x)(not-flag? solved?)) x ;scan board (if (position-flag? connected?) ;interesting part of fence? (Check n)(Check s)(Check e)(Check w) ; check neighbors (Check ne)(Check nw)(Check se)(Check sw) ; check neighbors ) ) ) (if (flag? solved?)(change-type Won z1)) ; signal end of game! (if (am-Blue?)(change-owner z1)) ) (define Check ;check for new link in fence (if (and (friend? $1)(not-position-flag? connected? $1)) ;new link? $1 (set-position-flag connected? true) (set-flag new-found? true) ;new link found (if (in-zone? Zone2)(set-flag solved? true)) ; other border reached (opposite $1) ) ) =========================================== This code can be easily adjusted to any similar game. Please feel free to use it! I am looking forward to see lots of connectivity games being created by all of you! The above code is from my trial version of a connectivity game called "Fence" which might grow into a proper Zillions-game soon... Cheers, Karl P.S. ================================================= I have also added for further clarification the complete code for this example game: ;********************************************************************** ;*** Fence *** ;*** V1.0 *** ;*** Copyright © Karl Scherer Jul 2002 *** ;*** Auckland, New Zealand *** ;*** *** ;*** more FREE GAMES SOFTWARE at my homepage: karl.kiwi.gen.nz *** ;*** also : real Puzzles and Boardgames *** ;********************************************************************** ; You need to purchase Zillions of Games to load this rules file ; Visit the Zillions web site at http://www.zillions-of-games.com (define am-Blue? (in-zone? Pzone a8)) (define am-Red? (not-in-zone? Pzone a8)) ;=========================== moves ===================================== (define Drop1 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (empty? n)(empty? s)(empty? e)(empty? w))) add )) (define Drop2 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (last-to? n)(last-to? e)(last-to? w)(last-to? s))) to (Checkwin) add )) ;............. submacros ............................ (define Checkwin ;check whether sides are "connected" (corner-touching dominoes O.K.) ; first we flag all friendly pieces that are on the left/top border a0 (while (on-board? x) x (if (and friend? (in-zone? Zone1)) (set-position-flag connected? true)) ) ;now we flag all fence pieces connected to the Zone1 border: (set-flag new-found? true) ;end of the fence not reached yet? (set-flag solved? false) ;borders connected? (while (and (flag? new-found?)(not-flag? solved?)) (set-flag new-found? false) ;initialize flag "new link found" a0 ;scan board (while (and (on-board? x)(not-flag? solved?)) x ;scan board (if (position-flag? connected?) ;interesting part of fence? (Check n)(Check s)(Check e)(Check w) ; check neighbors (Check ne)(Check nw)(Check se)(Check sw) ; check neighbors ) ) ) (if (flag? solved?)(change-type Won z1)) ; signal end of game! (if (am-Blue?)(change-owner z1)) ) (define Check ;check for new link in fence (if (and (friend? $1)(not-position-flag? connected? $1)) ;new link? $1 (set-position-flag connected? true) (set-flag new-found? true) ;new link found (if (in-zone? Zone2)(set-flag solved? true)) ; other border reached (opposite $1) ) ) ;=========================== pieces ===================================== (define Pdef (piece (name Dot) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Won) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Fence) (image Red "images\Fence\sqr.bmp" Blue "images\Fence\sqb.bmp") (drops (move-type Drop-1)(Drop1) (move-type Drop-2)(Drop2) ) ) ) ;============================= board ==================================== (define Bdef (image "images\Fence\bd9x9.bmp") (grid (start-rectangle 14 13 54 53) (dimensions ("a/b/c/d/e/f/g/h/i" (38 0)) ; files ("9/8/7/6/5/4/3/2/1" (0 38)) ; ranks ) (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0) (nw -1 -1) (ne 1 -1) (se 1 1) (sw -1 1) (x 1 0) ;scan ) ) (dummy a0) (positions (z1 0 -100 0 -100) ) (kill-positions a1 a9 i1 i9 ) (links x ;to scan board (a0 b1)(h1 a2)(i2 a3)(i3 a4)(i4 a5)(i5 a6)(i6 a7)(i7 a8)(i8 b9) ) (zone (name Zone1)(players Red) (positions a2 a3 a4 a5 a6 a7 a8)) ;western border (zone (name Zone2)(players Red) (positions i2 i3 i4 i5 i6 i7 i8)) ;eastern border (zone (name Zone1)(players Blue)(positions b9 c9 d9 e9 f9 g9 h9)) ;northern border (zone (name Zone2)(players Blue)(positions b1 c1 d1 e1 f1 g1 h1)) ;south border (zone (name Enemyzone)(players Red) (positions b9 c9 d9 e9 f9 g9 h9 b1 c1 d1 e1 f1 g1 h1)) (zone (name Enemyzone)(players Blue)(positions a2 a3 a4 a5 a6 a7 a8 i2 i3 i4 i5 i6 i7 i8)) (zone (name Offboard)(players Red Blue)(positions z1)) (zone (name Pzone)(players Blue)(positions b8)) ;player zone ) ;=========================== turn order ==================================== ;=========================== game =========================================== (game (title "Fence") (description "Object: Connect your two opposite borders. \ \You play as Red against Blue. \Red owns the left and right borders, Blue top and bottom. \Place a domino by clicking on two adjacent positions. \You cannot use your opponent's border positions. \ \The goal is to connect your two opposite borders. \Point-connections at corners are enough for a link. ") (history "Invented and implemented by Karl Scherer July 2002. \ \More freeware as well as real puzzle and games see my homepage: http://karl.kiwi.gen.nz .") ;(win-sound "Audio\Orchestra_CF.wav") (loss-sound "Audio\Orchestra_FC.wav") (click-sound "Audio\Pickup.wav") (release-sound "Audio\WoodThunk.wav") (pass-turn false) (animate-captures false) (animate-drops false) (players Red Blue) (turn-order (Red Drop-1)(Red Drop-2) (Blue Drop-1)(Blue Drop-2) ) (board (Bdef)) (board-setup (Red (Fence off 10000) (Dot z1) ) (Blue (Fence off 10000) ) ) (Pdef) (win-condition (Red Blue) (absolute-config Won (z1)) ) ) ;============================= variants ========================= ;(variant (title "Fence - variant 2") ;) |
Karl Scherer (Karl)
| | Posted on Thursday, July 18, 2002 - 6:13 am: | |
Of course the above technique can also be used to test connectivity between any two given positions on the board, not only to test the connectivity between opposite borders of the game. Cheers, Karl |
Karl Scherer (Karl)
| | Posted on Thursday, July 18, 2002 - 5:04 pm: | |
Bug fixed. The Checkwin macro given had a minor bug, which is corrected in the zrf code given below. (2 lines of code changed) The basic idea is still the same. The Checkwin macro did not check the last placed piece (now we "mark" it first in "Checkwin" and later include the marked position in the submacro "Check"). So here is the complete corrected zrf code: ;********************************************************************** ;*** Fence *** ;*** V1.0 *** ;*** Copyright © Karl Scherer Jul 2002 *** ;*** Auckland, New Zealand *** ;*** *** ;*** more FREE GAMES SOFTWARE at my homepage: karl.kiwi.gen.nz *** ;*** also : real Puzzles and Boardgames *** ;********************************************************************** ; You need to purchase Zillions of Games to load this rules file ; Visit the Zillions web site at http://www.zillions-of-games.com (define am-Blue? (in-zone? Pzone a8)) (define am-Red? (not-in-zone? Pzone a8)) ;=========================== moves ===================================== (define Drop1 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (empty? n)(empty? s)(empty? e)(empty? w))) add )) (define Drop2 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (last-to? n)(last-to? e)(last-to? w)(last-to? s))) to (Checkwin) add )) ;............. submacros ............................ (define Checkwin ;check whether sides are "connected" (corner-touching dominoes O.K.) (go to) mark ; first we flag all friendly pieces that are on the left/top border a0 (while (on-board? x) x (if (and friend? (in-zone? Zone1)) (set-position-flag connected? true)) ) ;now we flag all fence pieces connected to the Zone1 border: (set-flag new-found? true) ;end of the fence not reached yet? (set-flag solved? false) ;borders connected? (while (and (flag? new-found?)(not-flag? solved?)) (set-flag new-found? false) ;initialize flag "new link found" a0 ;scan board (while (and (on-board? x)(not-flag? solved?)) x ;scan board (if (position-flag? connected?) ;interesting part of fence? (Check n)(Check s)(Check e)(Check w) ; check neighbors (Check ne)(Check nw)(Check se)(Check sw) ; check neighbors ) ) ) (if (flag? solved?) (change-type Won z1) ; signal end of game! (if (am-Blue?)(change-owner z1)) ) ) (define Check ;check for new link in fence (if (and (or (marked? $1) (friend? $1))(not-position-flag? connected? $1)) ;new link? $1 (set-position-flag connected? true) (set-flag new-found? true) ;new link found (if (in-zone? Zone2)(set-flag solved? true)) ; other border reached (opposite $1) ) ) ;=========================== pieces ===================================== (define Pdef (piece (name Dot) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Won) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Fence) (image Red "images\Fence\sqr.bmp" Blue "images\Fence\sqb.bmp") (drops (move-type Drop-1)(Drop1) (move-type Drop-2)(Drop2) ) ) (piece (name sqg) (image Red "images\Fence\sqg.bmp" Blue "images\Fence\sqg.bmp") (drops (move-type Drop-1)(Drop1) (move-type Drop-2)(Drop2) ) ) ) ;============================= board ==================================== (define Bdef (image "images\Fence\bd9x9.bmp") (grid (start-rectangle 14 13 54 53) (dimensions ("a/b/c/d/e/f/g/h/i" (38 0)) ; files ("9/8/7/6/5/4/3/2/1" (0 38)) ; ranks ) (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0) (nw -1 -1) (ne 1 -1) (se 1 1) (sw -1 1) (x 1 0) ;scan ) ) (dummy a0) (positions (z1 0 -100 0 -100) ) (kill-positions a1 a9 i1 i9 ) (links x ;to scan board (a0 b1)(h1 a2)(i2 a3)(i3 a4)(i4 a5)(i5 a6)(i6 a7)(i7 a8)(i8 b9) ) (zone (name Zone1)(players Red) (positions a2 a3 a4 a5 a6 a7 a8)) ;western border (zone (name Zone2)(players Red) (positions i2 i3 i4 i5 i6 i7 i8)) ;eastern border (zone (name Zone1)(players Blue)(positions b9 c9 d9 e9 f9 g9 h9)) ;northern border (zone (name Zone2)(players Blue)(positions b1 c1 d1 e1 f1 g1 h1)) ;south border (zone (name Enemyzone)(players Red) (positions b9 c9 d9 e9 f9 g9 h9 b1 c1 d1 e1 f1 g1 h1)) (zone (name Enemyzone)(players Blue)(positions a2 a3 a4 a5 a6 a7 a8 i2 i3 i4 i5 i6 i7 i8)) (zone (name Offboard)(players Red Blue)(positions z1)) (zone (name Pzone)(players Blue)(positions b8)) ;player zone ) ;=========================== turn order ==================================== ;=========================== game =========================================== (game (title "Fence") (description "Object: Connect your two opposite borders. \ \You play as Red against Blue. \Red owns the left and right borders, Blue top and bottom. \Place a domino by clicking on two adjacent positions. \You cannot use your opponent's border positions. \ \The goal is to connect your two opposite borders. \Point-connections at corners are enough for a link. ") (history "Invented and implemented by Karl Scherer July 2002. \ \More freeware as well as real puzzle and games see my homepage: http://karl.kiwi.gen.nz .") ;(win-sound "Audio\Orchestra_CF.wav") (loss-sound "Audio\Orchestra_FC.wav") (click-sound "Audio\Pickup.wav") (release-sound "Audio\WoodThunk.wav") (pass-turn false) (animate-captures false) (animate-drops false) (players Red Blue) (turn-order (Red Drop-1)(Red Drop-2) (Blue Drop-1)(Blue Drop-2) ) (board (Bdef)) (board-setup (Red (Fence off 10000) (Dot z1) ) (Blue (Fence off 10000) ) ) (Pdef) (win-condition (Red Blue) (absolute-config Won (z1)) ) ) ;============================= variants ========================= ;(variant (title "Fence - variant 2") ;) |
Karl Scherer (Karl)
| | Posted on Thursday, July 18, 2002 - 5:30 pm: | |
No extra move, no "Referee" player necessary. I just want to mention here that the macro "Checkwin" also eliminates the need for any additional "referee" player or similar constructs (slows game down, obstructing the move list etc, complicated turn-order,...) like done in some games (e.g. Hex, Snakes,...). With the proposed Checkwin macro there are no extra dummy moves or Ref moves, not even one additional "change-type" command necessary for the checking of the connectivity. (only when the game is finished, there is one change-type). |
Karl Scherer (Karl)
New member Username: Karl
Post Number: 385 Registered: 9-2000
| | Posted on Friday, April 30, 2010 - 6:39 am: | |
Bug fixed Eric Duran remarked that the win-message was for the Red side only. The following version fixes that: ------------------------------------------------ ;********************************************************************** ;*** Fence *** ;*** V1.0 *** ;*** Copyright © Karl Scherer Jul 2002 *** ;*** Auckland, New Zealand *** ;*** *** ;*** more FREE GAMES SOFTWARE at my homepage: karl.kiwi.gen.nz *** ;*** also : real Puzzles and Boardgames *** ;********************************************************************** ; You need to purchase Zillions of Games to load this rules file ; Visit the Zillions web site at http://www.zillions-of-games.com (define am-Blue? (in-zone? Pzone a8)) (define am-Red? (not-in-zone? Pzone a8)) ;=========================== moves ===================================== (define Drop1 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (empty? n)(empty? s)(empty? e)(empty? w))) add )) (define Drop2 ( ;drop first half of domino (verify empty?) (verify (not-in-zone? Offboard)) (verify (not-in-zone? Enemyzone)) (verify (or (last-to? n)(last-to? e)(last-to? w)(last-to? s))) to (Checkwin) add )) ;............. submacros ............................ (define Checkwin ;check whether sides are "connected" (corner-touching dominoes O.K.) (go to) mark ; first we flag all friendly pieces that are on the left/top border a0 (while (on-board? x) x (if (and friend? (in-zone? Zone1)) (set-position-flag connected? true)) ) ;now we flag all fence pieces connected to the Zone1 border: (set-flag new-found? true) ;end of the fence not reached yet? (set-flag solved? false) ;borders connected? (while (and (flag? new-found?)(not-flag? solved?)) (set-flag new-found? false) ;initialize flag "new link found" a0 ;scan board (while (and (on-board? x)(not-flag? solved?)) x ;scan board (if (position-flag? connected?) ;interesting part of fence? (Check n)(Check s)(Check e)(Check w) ; check neighbors (Check ne)(Check nw)(Check se)(Check sw) ; check neighbors ) ) ) (if (flag? solved?) (create Won z1) ; signal end of game! ) ) (define Check ;check for new link in fence (if (and (or (marked? $1) (friend? $1))(not-position-flag? connected? $1)) ;new link? $1 (set-position-flag connected? true) (set-flag new-found? true) ;new link found (if (in-zone? Zone2)(set-flag solved? true)) ; other border reached (opposite $1) ) ) ;=========================== pieces ===================================== (define Pdef (piece (name Dot) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Won) (image Red "images\Fence\dot.bmp" Blue "images\Fence\dot.bmp")) (piece (name Fence) (image Red "images\Fence\sqr.bmp" Blue "images\Fence\sqb.bmp") (drops (move-type Drop-1)(Drop1) (move-type Drop-2)(Drop2) ) ) (piece (name sqg) (image Red "images\Fence\sqg.bmp" Blue "images\Fence\sqg.bmp") (drops (move-type Drop-1)(Drop1) (move-type Drop-2)(Drop2) ) ) ) ;============================= board ==================================== (define Bdef (image "images\Fence\bd9x9.bmp") (grid (start-rectangle 14 13 54 53) (dimensions ("a/b/c/d/e/f/g/h/i" (49 0)) ; files ("9/8/7/6/5/4/3/2/1" (0 49)) ; ranks ) (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0) (nw -1 -1) (ne 1 -1) (se 1 1) (sw -1 1) (x 1 0) ;scan ) ) (dummy a0) (positions (z1 0 -100 0 -100) ) (kill-positions a1 a9 i1 i9 ) (links x ;to scan board (a0 b1)(h1 a2)(i2 a3)(i3 a4)(i4 a5)(i5 a6)(i6 a7)(i7 a8)(i8 b9) ) (zone (name Zone1)(players Red) (positions a2 a3 a4 a5 a6 a7 a8)) ;western border (zone (name Zone2)(players Red) (positions i2 i3 i4 i5 i6 i7 i8)) ;eastern border (zone (name Zone1)(players Blue)(positions b9 c9 d9 e9 f9 g9 h9)) ;northern border (zone (name Zone2)(players Blue)(positions b1 c1 d1 e1 f1 g1 h1)) ;south border (zone (name Enemyzone)(players Red) (positions b9 c9 d9 e9 f9 g9 h9 b1 c1 d1 e1 f1 g1 h1)) (zone (name Enemyzone)(players Blue)(positions a2 a3 a4 a5 a6 a7 a8 i2 i3 i4 i5 i6 i7 i8)) (zone (name Offboard)(players Red Blue)(positions z1)) (zone (name Pzone)(players Blue)(positions b8)) ;player zone ) ;=========================== turn order ==================================== ;=========================== game =========================================== (game (title "Fence") (description "Object: Connect your two opposite borders. \ \You play as Red against Blue. \Red owns the left and right borders, Blue top and bottom. \Place a domino by clicking on two adjacent positions. \You cannot use your opponent's border positions. \ \The goal is to connect your two opposite borders. \Point-connections at corners are enough for a link. ") (history "Invented and implemented by Karl Scherer July 2002. \ \More freeware as well as real puzzle and games see my homepage: http://karl.kiwi.gen.nz . ") ;(win-sound "Audio\Orchestra_CF.wav") (loss-sound "Audio\Orchestra_FC.wav") (click-sound "Audio\Pickup.wav") (release-sound "Audio\WoodThunk.wav") (pass-turn false) (animate-captures false) (animate-drops false) (players Red Blue) (turn-order (Red Drop-1)(Red Drop-2) (Blue Drop-1)(Blue Drop-2) ) (board (Bdef)) (board-setup (Red (Fence off 10000) (Dot z1) ) (Blue (Fence off 10000) ) ) (Pdef) (win-condition (Red Blue) (absolute-config Won (z1)) ) ) ;============================= variants ========================= ;----------------------------------------------- ;Cheers, Karl |
|