1130tutorial11

1130tutorial11 - CSC1130Introductionto ComputerProgramming...

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

View Full Document Right Arrow Icon
    CSC1130 Introduction to  Computer Programming Tutorial Notes 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
    Outline Task 2 basic rules Implementation tips The instanceof keyword Polymorphism Array and Collection
Background image of page 2
    Fairy Chess We try to extend International Chess Add four more chess piece types Larger chess board
Background image of page 3

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

View Full DocumentRight Arrow Icon
    Chess Board
Background image of page 4
    Hopper Extend  Rider Unlimited steps each movement Capture enemy by jumping over a hurdle Some example hoppers Cannon Grasshopper Locust
Background image of page 5

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

View Full DocumentRight Arrow Icon
    Hoppers Cannon Move vertically and horizontally, movement rule (0,1)   Capture opponent any squares behind the hurdle  
Background image of page 6
    Hoppers Grasshopper Moves like a Queen, movement rule (0,1) and (1,1) ) Capture the piece one square behind the hurdle 
Background image of page 7

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

View Full DocumentRight Arrow Icon
    Hoppers Locust Moves like a Queen, movement rule (0,1) and (1,1) ) Capture an opponent hurdle Land on an empty square
Background image of page 8
    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
Background image of page 9

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

View Full DocumentRight Arrow Icon
    Class Diagram
Background image of page 10
    Class Diagram
Background image of page 11

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

View Full DocumentRight Arrow Icon
    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
Background image of page 12
    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
Background image of page 13

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

View Full DocumentRight Arrow Icon
    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)
Background image of page 14
    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
Background image of page 15

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

View Full DocumentRight Arrow Icon
    Cross Product find the direction pair (i, j) parallel with diff
Background image of page 16
Image of page 17
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 Right Arrow Icon
Ask a homework question - tutors are online