Friday, 21 December 2018

Google + Content reposting - May 16 2015


Digital and Interactive Games 2015, Term 2, Session 2
Bitwise Operations
Queue

& - and
| - or
XOR – xor
! - not


P    q    AND    OR    XOR    NOT     
0    0    0    0    1         
0    1    0    1    0         
1    0    0    1    0         
1    1    1    1    1      

http://i483.photobucket.com/albums/rr193/Brenorenz/W10S003_zpshaut6ljy.png

Ex
Bit 7 – 1 indicates the top of the door
Bit 3 – 0 indicates the bottom of the door
–    left hinge
top/bottom, left/right hinge


http://i483.photobucket.com/albums/rr193/Brenorenz/W10S004_zpsdv2cwffu.png

int topLeft = 0; 10001000
0000 0000 0000 0000
MSB           LSB
topLeft = 128 + 8; // set bit 7 and 3 on.


// check if bit 7 is on
if (topLeft & 128 == 128)

Shift left 10001000
    --------------
       00010000
---
char ch;

for (int i = 0; i < 10; i++) {
    ch = (char) ('x' + i);
    System.out.print(ch);
  
    ch = (char) ((int) ch OR 65503);
    System.out.print(ch);
}


1 1 1 1  1 1 1 1   1 0 1 1  1 1 1 1


char aDoor;

// bit 7 - top part of the door
//    - bottom part of the door
// bit 3 – 1 – left hinge
//


aDoor = 0;
aDoor = (char) ((int) aDoor | 128);
aDoor = (char) ((int) aDoor | 8);


Turn on - all to zero except the target bit, then OR it.
i.e. turn bit 3 on.
    Var | 00001000


Turn off – all to one except target bit, then AND it.
i.e. turn bit 6 off
    var & 10111111


Textbook Ch 5.


System.out.print(aDoor);
System.out.print(int) aDoor & (256 – 8);
System.out.print(int) aDoor;

// Turn it back on
aDoor = (char) ((int) aDoor | 8);

System.out.println();

// Shift 1 bit
aDoor = (char) ((int) aDoor << 1);
System.out.print((int) a Door);
System.out.print(ol);
aDoor = (char) ((int) aDoor >> 2);
System.out.print((int aDoor);


Queue

http://i483.photobucket.com/albums/rr193/Brenorenz/W10S005_zpsyxnsfo3h.png

remove + 20 is at position 0.


property: MAX_ITEMS
      : item[] int
      : begin int
      : end int
      : count int


Method : Add
       Remove
       get MaxItems : int
       getCount
       Search (int) : int

<a href="http://s483.photobucket.com/user/Brenorenz/media/W10S006_zpsda3c68xm.png.html" target="_blank"><img src="http://i483.photobucket.com/albums/rr193/Brenorenz/W10S006_zpsda3c68xm.png" border="0" alt=" photo W10S006_zpsda3c68xm.png"/></a>
http://i483.photobucket.com/albums/rr193/Brenorenz/W10S006_zpsda3c68xm.png

INVALID
–    99999

Que Sample
Queue
public class Queue {
    private int MAX_ITEMS = 20;
    private int count = 0;
    private int begin = 0;
    private int end = 0;
    private int INVALID = 99999;

    public void print() {

    }

    public boolean add(int value) {
        boolean result = false;
        if (count < MAX_ITEMS) {
            item[end] = value;
            ++end;
            result = true;
        }
        ++ count;
        return result;
    }

    public int getMaxItems() {
        return MAX_ITEMS;
    }

    public int getCount() {
        return count;
    }




Test cases
Overall scenarios
–    working
–    expected errors

(1)    Add an item to an empty queue
Values: 5, 10, 0, -20
Expected : B : MaxItem = 2    count = 0    peek = 99999
    A : MaxItem = 2    count = 0    peek = 99999
print →


B : MaxItem = 20    count = 1    peek = 5
A : MaxItem = 20    count = 1    peek = 5
print


(2)
    Add 20 items
    Then add 1 item

    B:
    print
    A: print


Stack


http://i483.photobucket.com/albums/rr193/Brenorenz/W10S007_zpssjrbmotw.png

Queue.java (part of)
public class Queue {
    private int MAX_ITEMS = 20;
    private int count = 0;
    private int item[] = new int{MAX_ITEMS];
    private int begin = 0;
    private int end = 0;
    private int INVALID = 99999;


    int index = begin;
    for (int i=0; i< count; ++i) {
        System.out.print[index] + “ ”);
        ++index;
        if (index == this.MAX_ITEMS) {
            index = 0;
        }
    }
}




#gamedesign   #gameprogramming   #java   #minecraft   #programming   #tafe  

Triangle.java
public class Triangle extends TwoDShape {
    string style;

    string type;

    Triangle() {
        type = “triangle”;
    }

    double area() {
        return.getWidth() * getHeight() / 2;
    }

    void showstyle() {
        System.out.Println(“Triangle is ” + style);
    }
}

Rectangle.java
class Rectangle extends TwoDShape {
    string type;

    Rectangle() {
        type = “Rectangle”
    }

    boolean isSquare() {
        if (getWidth() == getHeight() return true;
        return false;
    }

    double area() {
        return getWidth() * getHeight();
    }

}

GameConstants.java

final static public int WAITING_FOR_PLAYER = 1;
final static public int WAITING_FOR_DEALER = 1;
final static public int CHECKING_HAND_OVER = 1;
final static public int DEALER_HITTING = 1;
final static public int DISPLAYING_HANDING_RESULTS = 1;
final static public int EXITING = 1;
final static public int PLAYER_HITTING = 1;

Testfifteen.java
public class Testfifteen {
    public static void main (string[0] args) {
        Triangle t1 = new Triangle();
        Triangle t2 = new Triangle();

        t1.setWidth(4.0);
        t1.setHeight(4.0);
        t1.style = “filled”;

        t2.setWidth(8.0);
        t2.setHeight(12.0);
        t2.style = “outlined”;

        System.out.Println(“Info for t1: ”);
        t1.showStyle();
        t1.showDim();
        System.out.Println(“Area is: ” + t1.area());

        System.out.Println();


        System.out.Println(“Info for t2: ”);
        t2.showStyle();
        t2.showDim();
        System.out.Println.println(“Area is: ” + t2.area());

        Rectangle r1 = new Rectangle();
        r1.setWidth(3);
        r1.setHeight(4);
        r1.showDim();
        System.out.Println(“Area is ” + r1.area());
    }
}
Listing 5

Listing Five

#gamedesign   #gameprogramming   #java   #powershell   #programming   #tafe  





No comments:

Post a Comment