The Fighters’ Universe(simple verison) 十二月 10, 2007
Posted by 不雨 in Java, TextFighter.add a comment
The program can download in here.
This time TextFighter added boss player.
The rule is no change, but boss player can receives double hp and just take a halt damage.
output:
Welcome to Text Fighter!
Player1 is Dr Chan (10)
Player2 is Leo (10)
Player3 is Dr Wong(Boss) (10)
Player4 is Pak(Boss) (10)
Round1
Dr Chan attacks Dr Wong(Boss)
Dr Chan:11
Dr Wong(Boss):10
Pak(Boss) attacks Leo
Leo:9
Pak(Boss):12
Leo attacks Dr Wong(Boss)
Dr Wong(Boss):10
Leo:10
Pak(Boss) attacks Leo
Pak(Boss):16
Leo:8
Dr Chan:11
Leo:8
Dr Wong(Boss):10
Pak(Boss):16
Round2
Dr Chan attacks Pak(Boss)
Dr Chan:16
Pak(Boss):14
Pak(Boss) attacks Leo
Leo:2
Pak(Boss):26
Dr Wong(Boss) attacks Dr Chan
Dr Wong(Boss):22
Dr Chan:10
Leo attacks Pak(Boss)
Pak(Boss):14
Leo:26
Dr Chan:10
Leo:26
Dr Wong(Boss):22
Pak(Boss):14
Round3
Dr Chan attacks Pak(Boss)
Dr Chan:14
Pak(Boss):12
Dr Chan attacks Leo
Leo:14
Dr Chan:26
Pak(Boss) attacks Dr Wong(Boss)
Dr Wong(Boss):17
Pak(Boss):32
Pak(Boss) attacks Dr Wong(Boss)
Pak(Boss):62
Dr Wong(Boss):10
Dr Chan:26
Leo:14
Dr Wong(Boss):10
Pak(Boss):62
Round4
Dr Chan attacks Leo
Dr Chan:38
Leo:2
Leo attacks Dr Chan
Leo:38
Dr Chan:2
Dr Wong(Boss) attacks Dr Chan
Dr Wong(Boss):26
Dr Chan:-6
Pak(Boss) attacks Dr Wong(Boss)
Pak(Boss):134
Dr Wong(Boss):8
Dr Chan:-6
Leo:38
Dr Wong(Boss):8
Pak(Boss):134
GameOver
Dr Chan is dead.
Flow-shop problem 十二月 6, 2007
Posted by 不雨 in Genetic Algorithm.add a comment
PowerPoint in here.
The program you can download in here.
In this program, I was tried to write a genetic algorithm to solve flow-shop problem.
Flow-shop problem is try to sequencing the job sequence with more than two machines.
Because only have two machines we can use Johnson’s rule to solve it, so there are m machine(m should > 2) and j jobs(j should > 1) with several conditions need to be in place:
- The time for each job must be constant.
- The job times must be mutually exclusive of the job’s sequence.
- All jobs must go through first work center before going through the second work center.
- There must be no job priorities.
So in this program, I would tried to find out the best sequencing of jobs.
Here has a example with gantt chart:
In this picture, the table on the left hand side has shown the time each job need in every machine. And right hand side is a gantt chart for showing the total time of sequence job A-B-C.
Because we are sequence the job’s sequence, so there are j!(e.g. j=4, 4!=24) combination.
In this program, I have set the population sizes for 500, 10 jobs, 10 machines and run 10 generations. The probability of mutation and crossover are 0.1 and 0.8. All of these you can change in the top of Chromosome.java.
The program will output the work table first, and print out best sequence in each generation and finally will output over all the best.
The program still not find out the best one, only find a better one, so I think I still need to take notice of evaluate fitness.
This idea came from jijng’s Blog, but some pictures were missing, so many concepts were difficult to get, especially 3.3 how to calculate the fitness, this may the main problem of why my program didn’t as efficient as jijng’s work.
output:
| 0 1 2 3 4 5 6 7 8 9
|0 7 8 3 8 2 2 1 2 3 1
|1 2 8 9 5 6 7 8 5 1 7
|2 2 2 5 4 8 9 8 2 9 3
|3 7 1 9 5 7 4 7 5 4 2
|4 9 1 6 6 1 4 8 1 4 9
|5 5 8 9 7 4 2 4 1 3 9
|6 6 3 8 1 4 3 3 7 3 8
|7 2 4 9 7 4 8 2 5 3 2
|8 2 7 4 1 2 3 6 1 5 9
|9 2 6 9 9 6 6 3 9 1 7
Generation:1
The best one is 183
4 2 7 5 0 6 1 3 9 8
Generation:2
The best one is 182
0 6 2 9 1 4 7 3 5 8
Generation:3
The best one is 185
4 2 9 1 7 5 0 6 3 8
Generation:4
The best one is 188
4 2 9 1 7 8 6 3 5 0
Generation:5
The best one is 184
8 3 5 6 2 9 4 7 1 0
Generation:6
The best one is 184
4 7 6 2 9 3 1 5 0 8
Generation:7
The best one is 182
0 6 2 9 1 4 7 3 5 8
Generation:8
The best one is 188
4 6 8 2 9 7 5 3 1 0
Generation:9
The best one is 186
0 6 2 9 1 7 3 5 4 8
Generation:10
The best one is 182
0 6 2 9 1 4 7 5 3 8
Over all the best one is 182
0 6 2 9 1 4 7 3 5 8
Chapter6 Exercises 十一月 3, 2007
Posted by 不雨 in Java, ch06.add a comment
The Java file you can download here.
Here are two program, CAI.java and Guess.java.
CAI.java is a program to let student to learn multiplication. It will random to ask 10 question.
output:
Welcome for test of multiplication!
How much is 10 times 5
50
Keep UP the good work
How much is 2 times 1
2
Very good!
How much is 6 times 4
24
Very good!
How much is 9 times 1
9
Very good!
How much is 9 times 9
81
Excellent
How much is 4 times 1
4
Keep UP the good work
How much is 3 times 6
18
Nice work
How much is 7 times 7
49
Keep UP the good work
How much is 7 times 9
63
Nice work
How much is 9 times 6
54
Excellent
The percentage of correct responses is 100%
Try again?
1:yes
2:no
2
Thank you for using this program!
Guess.java will create a num between 1 and 1000 to let player guess.
output:
Guess the number between 1 and 1000:
500
Too high.Try again.
250
Too low.Try again.
375
Too low.Try again.
436
Too high.Try again.
405
Too high.Try again.
390
Too low.Try again.
398
Too low.Try again.
402
Too high.Try again.
400
Congratulations.You guessed the number!
Either you know the secret or you got lucky!
Play again?
1:Yes
2:No
2
Thank you for play!
Chapter6 Graphics Exercises 十一月 3, 2007
Posted by 不雨 in Java, ch06.add a comment
The Java file you can download here.
This program is tried to random two difference colours for draw a bulleye.
output:
Complex TextFighter 十月 17, 2007
Posted by 不雨 in Java, TextFighter.1 comment so far
The Java file you can download here.
This TextFighter is more funny, because there are four players and you can choose attack who and determine who win is using a game “Paper, Scissors, Rock”. The user may role Dr Chan to duel with Leo, Dr Wong, Pak(other philosophers) and the game will over when Dr Chan is dead or all philosophers are dead except Dr Chan. All the things is base on simple TextFigher.
Welcome to Text Fighter!
Player1 is Dr Chan (100)
Player2 is Leo (100)
Player3 is Dr Wong (100)
Player4 is Pak (100)
Round1
===Attack===
Who do you want to attack?
1:Leo
2:Dr Wong
3:Pak
2
1:Paper
2:Scissors
3:Rock
2
Dr Chan VS Dr Wong
SCISSORS VS ROCK
Dr Wong wins!
Dr Wong attacks Dr Chan
100 – 100
Damage is 1
Dr Chan:99
Dr Wong:101
Leo’s Thinking… /
Simple TextFighter 十月 17, 2007
Posted by 不雨 in Java, TextFighter.add a comment
The Java file you can download here.
This is a simple TextFighter, only 2 players and user may not have any action. There are two players and a random number to determine the attack success or not. The winner may add the difference between two players and the loser may subtract the difference. If the difference is 0, it may turn to 1.
Simple output:
Welcome to Text Fighter!
Player1 is Dr Chan (100)
Player2 is Leo (100)
Round1
===Attack===
Leo attacks Dr Chan
Damage is 1
Dr Chan:99
Leo:101
Chapter4 Graphics Exercises 十月 17, 2007
Posted by 不雨 in Java, ch04.add a comment
The Java file you can download here.
There are four files: DrawPanelA, DrawPanelATest, DrawPanelB, DrawPanelBTest.
These all are using Java:How to Program chapter4 skill to write.
DrawPanelA output:
DrawPanelB output:
Chapter4 Exercises 十月 17, 2007
Posted by 不雨 in Java, ch04.2 comments
The Java file you can download here.
There are two programs: Printstar and Multiples.
These all are using Java:How to Program chapter4 skill to write.
Printstar Simple output:
|* * * * * * * *
| * * * * * * * *
|* * * * * * * *
| * * * * * * * *
|* * * * * * * *
| * * * * * * * *
|* * * * * * * *
| * * * * * * * *
Multiples:
This program will keep displaying the multiples of 2 by using infinite loop.
Simple output:
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
32768
65536
131072
262144
524288
1048576
2097152
4194304
8388608
16777216
33554432
67108864
134217728
268435456
536870912
1073741824
-2147483648
Chapter3 Exercise 十月 17, 2007
Posted by 不雨 in Java, ch03.add a comment
The Java file you can download here.
There are two files: Employee and EmployeeTest.
These all are using Java:How to Program chapter3 skill to write.
This exercise is tried to create a constructor that initializes three instance variables: first name(String), last name(String) and monthly salary(double). The program will display employee’s yearly salary. If employee’s monthly salary is not positive, it will turn to 0.
Simple output:
Wai Kwok’s yearly salary is 0.00
Y Tsoi’s yearly salary is 120000.00
After increase salary, Wai Kwok’s yearly salary is 0.00
After increase salary, Y Tsoi’s yearly salary is 132000.0
Chapter2 Exercises 十月 17, 2007
Posted by 不雨 in Java, ch02.add a comment
The Java file you can download here.
There are four programs: Pi, Counter, Separation and Discrimination.
These all are using Java:How to Program chapter2 skill to write.
Pi:
Pi.Java is tried to use the PI values, which is already defined in package java.lang.
Simple output:
Enter the radius: 2
diameter=4.00
circumference=12.57
area=12.57
Counter:
Counter.Java is using to count how many positive numbers , negative numbers and zero.
After running the program, you should type in 5 numbers.
Simple output:
Enter 5 numbers:
10
-10
0
1
-1
Positive:2
Negative:2
Zero:1
Separation:
This program will ask you to type in a 5 digit number and it will separate the number to 5 numbers.
Simple output:
Enter a 5 digit number:
12345
1 2 3 4 5
Discrimination:
This program can discriminate the number you input is even/odd.
Simple output:
Enter a number:12
12 is a even.