;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Combat (C) 1997 David Wallace Croft ;; 1997-11-30 ;; Language: Java Expert System Shell (JESS) CLIPS variant ;; ;; Attacks can come from four directions: front, back, left, right. ;; Attacks to your back do the most damage. ;; Attacks to your left are shielded. ;; ;; Attacks can only be made to the front. ;; Movements can only be made to the front. ;; Turns can only be made to the left or the right. ;; ;; ZERO ENEMY RULES ;; (0000) If no enemies are around, wander. ;; ;; SINGLE ENEMY RULES ;; (1000) If the only enemy is to your front, attack. ;; (1001) If the only enemy is to your back, turn left. ;; (1002) If the only enemy is to your left, turn left. ;; (1003) If the only enemy is to your right, turn right. ;; ;; DOUBLE ENEMY RULES ;; (2000) If neither enemy is facing you and one of the enemies ;; is in front of you, attack. ;; (2001) If neither enemy is facing you and neither is in front ;; of you and an enemy is to the left of you, turn left. ;; (2002) If neither enemy is facing you and neither is in front ;; of you or to your left, turn right. ;; (2003) If only one of the enemies is facing you, treat that ;; enemy using the single enemy rules and ignore the ;; others. ;; (2004) If both enemies are facing you and one is to your front ;; and the other is to your right, turn right. ;; (2005) If both enemies are facing you and one is to your front ;; and the other is to your left, attack. ;; (2006) If both enemies are facing you and one is to your left ;; and the other is to your back, turn left. ;; (2007) If both enemies are facing you and one is to your right ;; and the other is to your back, turn right. ;; (2008) If both enemies are facing you and one is to your right ;; and the other is to your left, advance. ;; (2009) If both enemies are facing you and one is to your front ;; and the other is to your back, turn left. ;; ;; RULE SLOT SYMBOLS ;; ;; c = enemy count: 0, 1, or 2 ;; ;; f = front: e or z ;; r = right: e or z ;; b = back : e or z ;; l = left : e or z ;; (e = enemy) ;; (z = empty) ;; ;; F = front: 0 or 1 ;; R = right: 0 or 1 ;; B = back : 0 or 1 ;; L = left : 0 or 1 ;; (0 = enemy not facing you) ;; (1 = enemy facing you) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ( watch all ) ( deftemplate state "State" ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( slot c ( type NUMBER ) ( default 0 ) ) ( slot f ( type SYMBOL ) ( default z ) ) ( slot r ( type SYMBOL ) ( default z ) ) ( slot b ( type SYMBOL ) ( default z ) ) ( slot l ( type SYMBOL ) ( default z ) ) ( slot F ( type NUMBER ) ( default 0 ) ) ( slot R ( type NUMBER ) ( default 0 ) ) ( slot B ( type NUMBER ) ( default 0 ) ) ( slot L ( type NUMBER ) ( default 0 ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( defrule rule_2009 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2009) If both enemies are facing you and one is to your front ;; and the other is to your back, turn left. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( f e ) ( F 1 ) ( b e ) ( B 1 ) ) => ( printout t "Left" crlf ) ) ( defrule rule_2008 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2008) If both enemies are facing you and one is to your right ;; and the other is to your left, advance. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( l e ) ( L 1 ) ( r e ) ( R 1 ) ) => ( printout t "Advance" crlf ) ) ( defrule rule_2007 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2007) If both enemies are facing you and one is to your right ;; and the other is to your back, turn right. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( b e ) ( B 1 ) ( r e ) ( R 1 ) ) => ( printout t "Right" crlf ) ) ( defrule rule_2006 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2006) If both enemies are facing you and one is to your left ;; and the other is to your back, turn left. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( b e ) ( B 1 ) ( l e ) ( L 1 ) ) => ( printout t "Left" crlf ) ) ( defrule rule_2005 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2005) If both enemies are facing you and one is to your front ;; and the other is to your left, attack. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( f e ) ( F 1 ) ( l e ) ( L 1 ) ) => ( printout t "Attack" crlf ) ) ( defrule rule_2004 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2004) If both enemies are facing you and one is to your front ;; and the other is to your right, turn right. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( f e ) ( F 1 ) ( r e ) ( R 1 ) ) => ( printout t "Right" crlf ) ) ( defrule rule_2003L ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2003) If only one of the enemies is facing you, treat that ;; enemy using the single enemy rules and ignore the ;; others. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ?state <- ( state ( c 2 ) ( l e ) ( L 1 ) ( R 0 ) ( B 0 ) ( F 0 ) ) => ( modify ?state ( c 1 ) ( l e ) ( r z ) ( b z ) ( f z ) ) ) ( defrule rule_2003B ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2003) If only one of the enemies is facing you, treat that ;; enemy using the single enemy rules and ignore the ;; others. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ?state <- ( state ( c 2 ) ( b e ) ( B 1 ) ( R 0 ) ( F 0 ) ( L 0 ) ) => ( modify ?state ( c 1 ) ( b e ) ( f z ) ( b z ) ( l z ) ) ) ( defrule rule_2003R ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2003) If only one of the enemies is facing you, treat that ;; enemy using the single enemy rules and ignore the ;; others. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ?state <- ( state ( c 2 ) ( r e ) ( R 1 ) ( F 0 ) ( B 0 ) ( L 0 ) ) => ( modify ?state ( c 1 ) ( r e ) ( f z ) ( b z ) ( l z ) ) ) ( defrule rule_2003F ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2003) If only one of the enemies is facing you, treat that ;; enemy using the single enemy rules and ignore the ;; others. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ?state <- ( state ( c 2 ) ( f e ) ( F 1 ) ( R 0 ) ( B 0 ) ( L 0 ) ) => ( modify ?state ( c 1 ) ( f e ) ( r z ) ( b z ) ( l z ) ) ) ( defrule rule_2002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2002) If neither enemy is facing you and neither is in front ;; of you or to your left, turn right. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( F 0 ) ( R 0 ) ( B 0 ) ( L 0 ) ( f ~e ) ( l ~e ) ) => ( printout t "Right" crlf ) ) ( defrule rule_2001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2001) If neither enemy is facing you and neither is in front ;; of you and an enemy is to the left of you, turn left. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( F 0 ) ( R 0 ) ( B 0 ) ( L 0 ) ( f ~e ) ( l e ) ) => ( printout t "Left" crlf ) ) ( defrule rule_2000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (2000) If neither enemy is facing you and one of the enemies ;; is in front of you, attack. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 2 ) ( f e ) ( F 0 ) ( R 0 ) ( B 0 ) ( L 0 ) ) => ( printout t "Attack" crlf ) ) ( defrule rule_1003 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (1003) If the only enemy is to your right, turn right. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 1 ) ( r e ) ) => ( printout t "Right" crlf ) ) ( defrule rule_1002 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (1002) If the only enemy is to your left, turn left. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 1 ) ( l e ) ) => ( printout t "Left" crlf ) ) ( defrule rule_1001 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (1001) If the only enemy is to your back, turn left. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 1 ) ( b e ) ) => ( printout t "Left" crlf ) ) ( defrule rule_1000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (1000) If the only enemy is to your front, attack. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 1 ) ( f e ) ) => ( printout t "Attack" crlf ) ) ( defrule rule_0000 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; (0000) If no enemies are around, wander. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( state ( c 0 ) ) => ( printout t "Wander" crlf ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( deffacts query ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test queries. Unremark one at a time. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ( state ( c 2 ) ( l e ) ( L 0 ) ( r e ) ( R 0 ) ) ; ( state ( c 2 ) ( l e ) ( L 0 ) ( r e ) ( R 1 ) ) ( state ( c 2 ) ( b e ) ( B 1 ) ( f e ) ( F 1 ) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ( reset ) ( run ) ( facts )