1130tutorial11

# 1130tutorial11 - CSC1130Introductionto ComputerProgramming...

This preview shows pages 1–17. Sign up to view the full content.

CSC1130 Introduction to  Computer Programming Tutorial Notes 11

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Outline Task 2 basic rules Implementation tips The instanceof keyword Polymorphism Array and Collection
Fairy Chess We try to extend International Chess Add four more chess piece types Larger chess board

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Chess Board
Hopper Extend  Rider Unlimited steps each movement Capture enemy by jumping over a hurdle Some example hoppers Cannon Grasshopper Locust

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Hoppers Cannon Move vertically and horizontally, movement rule (0,1)   Capture opponent any squares behind the hurdle
Hoppers Grasshopper Moves like a Queen, movement rule (0,1) and (1,1) ) Capture the piece one square behind the hurdle

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Hoppers Locust Moves like a Queen, movement rule (0,1) and (1,1) ) Capture an opponent hurdle Land on an empty square
Chinese Knight Special Case of Knight Same as “Horse” in Xiang qi More restirction than Knight Can't move to the two directions where there is a piece  neighboring to the Chinese Knight

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Class Diagram
Class Diagram

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Implementation Tips Rider  Class addMoveRule(int i, int j) a determineMovingDirection(Point  target ) Hopper  Class getHurdle(Point  target , Point  direction ) ChineseKnight  Class canMove(Point  target) t
Rider class addMoveRule(int i, int j) a for convenience of checking add pair (i, j), (j, i), (-i, j), (-j, i) to rule list determineMovingDirection(Point  target ) Check whether the  target  to move is allowed Compare the difference with all direction pairs in moveAllowed  list If allowed, return the direction pair (i,j) I Otherwise, return null

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Compare Direction Calculate the difference (diff.x, diff.y) = (target.x, target.y) – (cur.x, cur.y) How to compare  diff  and  movement rule (i,j) GCD ( greatest common divisor ) Cross Product (similar to finding same slope)
GCD GCD method (3,9) can match the rule (1,3) Get GCD(3,9)=3 then (3,9)/3 = (1,3) How to calculate GCD(x,y) Recall your math knowledge

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Cross Product find the direction pair (i, j) parallel with diff
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/28/2010 for the course CSC CSC1110 taught by Professor Cjyuan during the Fall '06 term at CUHK.

### Page1 / 44

1130tutorial11 - CSC1130Introductionto ComputerProgramming...

This preview shows document pages 1 - 17. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online