Help with a complex move Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Designing Games for Zillions » Help with a complex move « Previous Next »

Author Message
Joshua Taylor (Archmageomega)
Posted on Saturday, August 27, 2005 - 11:10 pm:   

I've got a game I'm trying to write, but the moves are very complex algorithmically.

Specifically, one of the moves requires moving three pieces as one, one, two or three spaces (that part works), checking if that move caused any captures (by sandwiching, that works too) and then possibly changing the sides of some neutral pieces (this is the part I need help with).

The piece in question is a boat. It's three units long and is a neutral piece by itself. Other pieces move onto it and control it. If there are pieces of more than one color on it, it can't move. It slides along in the direction it's facing one space for each piece controlling it (but it doesn't have to move all the way). The empty pieces of the boats are (currently) owned by the player that last stood on them but it is possible to have a white piece in the middle of an empty black boat and White wouldn't be able to move it (which isn't how it should be).

Actually coding the move logic isn't so hard but what I've written crashes Zillions. I think it generates too much code once all the macros are expanded. Does anyone have any advice on how to resolve this?
Joshua Taylor (Archmageomega)
Posted on Sunday, August 28, 2005 - 2:09 am:   

BTW, I can get this all to work with a couple of random players to fix the board between turns, but that slows down move generation and somewhat confuses the AI.
L. Lynn Smith (Interrupt27)
Posted on Sunday, August 28, 2005 - 9:58 am:   

Don't check for ownership of those particular pieces but for occupancy by the opponent.

I would actually need to see the current code to make a proper evaluation.
Joshua Taylor (Archmageomega)
Posted on Sunday, August 28, 2005 - 12:44 pm:   

Thanks for the quick reply.

I've got my own macros for checking for friends, enemies and empty boats. The problem is, if white has a piece in the middle of an otherwise empty boat and black owns one end of the boat, white can't move that piece to make the boat move.

Anyway, here's the code in question:
 
(define friendly?
(and friend? (or (piece? BoatL) (piece? BoatLR) (piece? BoatR) (piece? BoatU) (piece? BoatUD) (piece? BoatD))))

(define hostile?
(and enemy? (or (piece? BoatL) (piece? BoatLR) (piece? BoatR) (piece? BoatU) (piece? BoatUD) (piece? BoatD))))

(define empty-boat?
(or (piece? EmptyBoatL) (piece? EmptyBoatLR) (piece? EmptyBoatR) (piece? EmptyBoatU) (piece? EmptyBoatUD) (piece? EmptyBoatD)))

(define inc-count
(if (not-flag? count1) (set-flag count1 true) else
(if (not-flag? count2) (set-flag count2 true) else
(set-flag count3 true))))

(define make-empty
(if (piece? BoatL) (create EmptyBoatL))
(if (piece? BoatLR) (create EmptyBoatLR))
(if (piece? BoatR) (create EmptyBoatR))
(if (piece? BoatU) (create EmptyBoatU))
(if (piece? BoatUD) (create EmptyBoatUD))
(if (piece? BoatD) (create EmptyBoatD)))


(define move-here
(if (piece? EmptyBoatL) (add BoatL))
(if (piece? EmptyBoatLR) (add BoatLR))
(if (piece? EmptyBoatR) (add BoatR))
(if (piece? EmptyBoatU) (add BoatU))
(if (piece? EmptyBoatUD) (add BoatUD))
(if (piece? EmptyBoatD) (add BoatD)))

(define check-single-capture
(go to) $1 (if (hostile?) $1
(if (friendly?) (opposite $1) (make-empty))))

(define check-single-captures
(go from)
(if (friendly?)
(check-single-capture n)
(check-single-capture ne)
(check-single-capture e)
(check-single-capture se)
(check-single-capture s)
(check-single-capture sw)
(check-single-capture w)
(check-single-capture nw)
(go to)))

(define move-guy-single
((make-empty) $1 (verify (empty-boat?)) to (check-single-captures) (move-here)))

(define clear-flags
(set-flag count1 false) (set-flag count2 false) (set-flag count3 false) (set-flag contested false))

(define set-flags
(clear-flags)
(if (friendly?) (inc-count)) (if (hostile?) (set-flag contested true)) (opposite $1)
(if (friendly?) (inc-count)) (if (hostile?) (set-flag contested true)) (opposite $1)
(if (friendly?) (inc-count)) (if (hostile?) (set-flag contested true)))

(define move-boat-single
((set-flags $1) (verify (not-flag? contested)) back
(if (flag? count1) from $1 (verify empty?) to (check-single-captures) cascade back
(opposite $1) from $1 to (check-single-captures) cascade back
(opposite $1) (opposite $1) from $1 to (check-single-captures) add) back
(if (flag? count2) from $1 $1 (verify empty?) to (check-single-captures) cascade back
(opposite $1) from $1 $1 to (check-single-captures) cascade back
(opposite $1) (opposite $1) from $1 $1 to (check-single-captures) add) back
(if (flag? count3) from $1 $1 $1 (verify empty?) to (check-single-captures) cascade back
(opposite $1) from $1 $1 $1 to (check-single-captures) cascade back
(opposite $1) (opposite $1) from $1 $1 $1 to (check-single-captures) add)))

(define guy-moves-single
(move-guy-single n)
(move-guy-single ne)
(move-guy-single e)
(move-guy-single se)
(move-guy-single s)
(move-guy-single sw)
(move-guy-single w)
(move-guy-single nw))
(game
.
.
.
(option "discard cascades" true)

(piece
(name BoatL)
(image White "images/WhiteBoatL.bmp" Black "images/BlackBoatL.bmp")
(moves
(guy-moves-single)
(move-boat-single w)))

(piece
(name BoatLR)
(image White "images/WhiteBoatLR.bmp" Black "images/BlackBoatLR.bmp")
(moves
(guy-moves-single)))

(piece
(name BoatR)
(image White "images/WhiteBoatR.bmp" Black "images/BlackBoatR.bmp")
(moves
(guy-moves-single)
(move-boat-single e)))

(piece
(name BoatU)
(image White "images/WhiteBoatU.bmp" Black "images/BlackBoatU.bmp")
(moves
(guy-moves-single)
(move-boat-single n)))

(piece
(name BoatUD)
(image White "images/WhiteBoatUD.bmp" Black "images/BlackBoatUD.bmp")
(moves
(guy-moves-single)))

(piece
(name BoatD)
(image White "images/WhiteBoatD.bmp" Black "images/BlackBoatD.bmp")
(moves
(guy-moves-single)
(move-boat-single s)))

(piece
(name EmptyBoatL)
(image White "images/EmptyBoatL.bmp" Black "images/EmptyBoatL.bmp")
(moves
(move-boat-single w)))

(piece
(name EmptyBoatLR)
(image White "images/EmptyBoatLR.bmp" Black "images/EmptyBoatLR.bmp"))

(piece
(name EmptyBoatR)
(image White "images/EmptyBoatR.bmp" Black "images/EmptyBoatR.bmp")
(moves
(move-boat-single e)))

(piece
(name EmptyBoatU)
(image White "images/EmptyBoatU.bmp" Black "images/EmptyBoatU.bmp")
(moves
(move-boat-single n)))

(piece
(name EmptyBoatUD)
(image White "images/EmptyBoatUD.bmp" Black "images/EmptyBoatUD.bmp"))

(piece
(name EmptyBoatD)
(image White "images/EmptyBoatD.bmp" Black "images/EmptyBoatD.bmp")
(moves
(move-boat-single s)))

.
.
.
Joshua Taylor (Archmageomega)
Posted on Sunday, August 28, 2005 - 9:01 pm:   

Well, I have a fully functional version of the game (AFAIK) but the two random players are slowing the AI down a lot. I'll probably still post the game here soon.

Add Your Message Here
Post:
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: