Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Java Programming > Java Forum > รบกวนผู้รู้เรื่อง java แกะโค้ดให้หน่อยค่ะพอดีต้องส่งงานแล้วไม่เข้าใจโค้ดค่ะ



 

รบกวนผู้รู้เรื่อง java แกะโค้ดให้หน่อยค่ะพอดีต้องส่งงานแล้วไม่เข้าใจโค้ดค่ะ

 



Topic : 048619



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์




รบกวนผู้รู้เรื่อง java แกะโค้ดให้หน่อยค่ะ

{
static final int GF_ZERO = 23;
static final int GF_ONE = 46;

protected static java.awt.geom.Rectangle2D.Double _fieldRect;
protected static Point2D.Double _myLocation;
protected static HashMap _enemyLocationsByName = new HashMap();
protected static double _randomDirChangeAmount;
protected long _timeSinceDirChangeCounter;
protected static double _lastHeading;
protected ArrayList _recentLocations;

protected double _targetRating = Double.POSITIVE_INFINITY;
protected static String _targetName = "";

protected static final double WAVE_BULLET_POWER = 1.99;
protected static final double WAVE_BULLET_VELOCITY = 14.03;
protected static final double WAVE_MAX_ESCAPE_ANGLE = 0.62;
protected static double _bulletPower;

private static int _radarDirection = 1;

public void run() {
setAdjustGunForRobotTurn(true);
setAdjustRadarForGunTurn(true);
setColors(new Color(255, 192, 203), new Color(192, 255, 62), new Color(255, 255, 255),new Color(255, 165, 0),new Color(255,255,255));
// (pink,Turquoise1,red,or,white)
_recentLocations = new ArrayList();

_fieldRect = new java.awt.geom.Rectangle2D.Double(30, 30,
getBattleFieldWidth() - 60, getBattleFieldHeight() - 60);

do {
setFireBullet(_bulletPower);
setTurnRadarRight(45 * _radarDirection);
move();
execute();
} while (true);
}

public void onScannedRobot(ScannedRobotEvent e) {
String eName = e.getName();
double eDistance = e.getDistance();
double eEnergy = e.getEnergy();
double eVelocity = e.getVelocity();


////////////////////////////////////////////////
// General stuff
////////////////////////////////////////////////

double enemyAbsoluteBearing =
e.getBearingRadians() + getHeadingRadians();

if (!_enemyLocationsByName.containsKey(eName)) {
_enemyLocationsByName.put(eName, new EnemyData());
}
EnemyData eData = (EnemyData)_enemyLocationsByName.get(eName);
eData.alive = true;
eData.location = project(_myLocation, enemyAbsoluteBearing, eDistance);
double absSinRelativeHeading = Math.abs(Math.sin(e.getHeadingRadians()
- enemyAbsoluteBearing));
eData.energy = eEnergy;

if (getOthers() == 1 ||
(_targetName.equals(eName) &&
(eDistance < 300 || (getGunHeat() < .8 && getOthers() <= 5)))) {

_radarDirection *= -1;
}


////////////////////////////////////////////////
// Gun wave creation
////////////////////////////////////////////////

MicroWave w;
addCustomEvent(w = new MicroWave());
w.targetName = eName;
w.sourceLocation = _myLocation;
w.directAngle = enemyAbsoluteBearing;
w.orientation = sign((eVelocity)*Math.sin(e.getHeadingRadians() - enemyAbsoluteBearing));

w.waveGuessFactors = eData.gunStats[(int)Math.abs(eVelocity) / 3][(int)(eDistance / 300)][(int)Math.min(2, absSinRelativeHeading * 3)];


////////////////////////////////////////////////
// Target selection and actual firing.
////////////////////////////////////////////////

double thisRating = (eEnergy * square(eDistance));
if (thisRating < (_targetRating * .8) || eName.equals(_targetName)) {
_targetRating = thisRating;
_targetName = eName;
}

if (_targetName.equals(eName)) {

_bulletPower = 1.99;

if (eDistance < 250 || getOthers() >= 6) {
_bulletPower = 3;
}

if (eDistance > 600 && (getOthers() <= 2)) {
_bulletPower = 1.4;
}

if (getEnergy() < 30 && eEnergy > getEnergy()) {
_bulletPower = Math.min(_bulletPower, 2 - ((33 - getEnergy()) / 15));
}

int bestGF = GF_ZERO;
double bestGFRank = 0;
for (int x = 0; x < GF_ONE; x++) {
if (w.waveGuessFactors[x] > bestGFRank) {
bestGFRank = w.waveGuessFactors[x];
bestGF = x;
}
}

setTurnGunRightRadians(Utils.normalRelativeAngle(
enemyAbsoluteBearing - getGunHeadingRadians() +
(e.getEnergy() > 0 ?
(w.orientation
* (maxEscapeAngle(bulletVelocity(_bulletPower)) / GF_ZERO)
* (bestGF - GF_ZERO)) : 0)));
}
}

public void onRobotDeath(RobotDeathEvent e) {
String eName = e.getName();

if (_targetName.equals(eName)) {
_targetName = "";
_targetRating = Double.POSITIVE_INFINITY;
}

((EnemyData)_enemyLocationsByName.get(eName)).alive = false;
}

protected void move() {
_myLocation = new Point2D.Double(getX(), getY());

if (Math.random() > 0.9) {
_recentLocations.add(0, _myLocation);
}

double bestRisk = Double.POSITIVE_INFINITY;
double bestAngle = 0;
double currentHeading =
getHeadingRadians() + (getVelocity() < 0?Math.PI:0);

Object[] enemies =
(_enemyLocationsByName.values().toArray());

_timeSinceDirChangeCounter++;
if (Math.abs(Utils.normalRelativeAngle(currentHeading - _lastHeading))
> Math.PI / 4) {
_timeSinceDirChangeCounter = 0;
_randomDirChangeAmount = (Math.random() * Math.random() * 50);
}

for (double x = 0; x < 2; x += .04) {
double testAngle = x * Math.PI;
Point2D.Double testPoint = project(_myLocation, testAngle,
50 + Math.random() * 200);

if (_fieldRect.contains(testPoint)) {
double testRisk = 0;

for (int y = 0; y < enemies.length; y++) {
EnemyData eData = ((EnemyData)enemies[y]);
if (eData.alive) {
double distSquaredToEnemy =
testPoint.distanceSq(eData.location);

testRisk +=
((limit(0.5, (eData.energy / getEnergy()), 2)
/ distSquaredToEnemy))
* (1 + square(Math.cos(absoluteBearing(
_myLocation, eData.location) - testAngle)))
;
}
}

if (Math.abs(Utils.normalRelativeAngle(currentHeading
- testAngle)) < (Math.PI / 4) && getOthers() <= 6) {
testRisk /= 2;
if (_timeSinceDirChangeCounter > _randomDirChangeAmount) {
testRisk *= 20;
}
}

try {
for (int z = 0; z < 4 && z < _recentLocations.size(); z++) {
testRisk *= (1 + (((400) - (50 * z)) / (testPoint.distanceSq((Point2D.Double)_recentLocations.get(z)))));
}
} catch (Exception e) { }

if (testRisk < bestRisk) {
bestRisk = testRisk;
bestAngle = x * Math.PI;
}
}
}

_lastHeading = currentHeading;

moveWithBackAsFront(bestAngle);
}

private static double absoluteBearing(Point2D.Double source, Point2D.Double target) {
return Math.atan2(target.x - source.x, target.y - source.y);
}


void moveWithBackAsFront(double bearing) {
double angle = Utils.normalRelativeAngle(bearing - getHeadingRadians());
double turnAngle;
setTurnRightRadians(turnAngle = Math.atan(Math.tan(angle)));
setAhead((angle == turnAngle) ? 100 : -100);
}

protected static Point2D.Double project(Point2D.Double sourceLocation, double angle, double length) {
return new Point2D.Double(sourceLocation.x + Math.sin(angle) * length,
sourceLocation.y + Math.cos(angle) * length);
}

private static double maxEscapeAngle(double velocity) {
return Math.asin(8.0/velocity);
}

protected static double bulletVelocity(double power) {
return (20.0 - (3.0*power));
}

static int sign(double d) {
if (d >= 0) return 1;
return-1;
}

static double square(double d) {
return d * d;
}

protected static double limit(double min, double value, double max) {
return Math.max(min, Math.min(value, max));
}

class MicroWave extends Condition {
String targetName;
Point2D.Double sourceLocation;
long[] waveGuessFactors;
double bulletVelocity, directAngle, distance;
int orientation;

public boolean test(){
try {
Point2D.Double enemyLocation =
((EnemyData)_enemyLocationsByName.get(targetName)).location;
if ((enemyLocation).distance(sourceLocation)
<= (distance+=WAVE_BULLET_VELOCITY) + (WAVE_BULLET_VELOCITY/2)) {
try {
double guessFactor = (Utils.normalRelativeAngle(
absoluteBearing(sourceLocation, enemyLocation)
- directAngle) * orientation) / WAVE_MAX_ESCAPE_ANGLE;
int guessFactorIndex = (int)((guessFactor * GF_ZERO) + GF_ZERO);
waveGuessFactors[guessFactorIndex]++;
/*
for (int x = GF_ONE - 1; x >= 0; x--) {
waveGuessFactors[x] +=
(1D / (square(x - guessFactorIndex) + 1));
// waveGuessFactors[x] = ((waveGuessFactors[x] * 200) +
// (1D / (square(x - guessFactorIndex) + 1)))
// / 201;
}
*/
} catch (Exception e) { }
removeCustomEvent(this);
}
} catch (Exception e) { }
return false;
}
}

class EnemyData {
protected long[][][][] gunStats = new long[3][5][3][GF_ONE+1];

boolean alive;
Point2D.Double location;
double energy;
}
}



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-09-11 21:49:50 By : pigletpink View : 2551 Reply : 1
 

 

No. 1



โพสกระทู้ ( 3,468 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter

เป็นการเรนเดอร์ เกมครับ โดยใช้ เธรด ให้มันคำนวนอย่างต่อเนื่อง






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-09-11 22:03:38 By : pjgunner.com
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนผู้รู้เรื่อง java แกะโค้ดให้หน่อยค่ะพอดีต้องส่งงานแล้วไม่เข้าใจโค้ดค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่