请高手给个robocode的原代码

请高手给个robocode的原代码,第1张

package robot37

import robocode.*

import java.awt.geom.Point2D

import java.awt.Color

public class A extends AdvancedRobot

{

double moveDirection

enemyStat enemy = new enemyStat()

public void run()

{

setBodyColor(Color.yellow)

setGunColor(Color.YELLOW)

setRadarColor(Color.YELLOW)

setScanColor(Color.GREEN)

setBulletColor(Color.YELLOW)

setAdjustGunForRobotTurn(true)

setAdjustRadarForGunTurn(true)

setTurnRadarRightRadians(2*Math.PI) //让雷达一直转

while(true)

{

doFire()

doScannedRobot()

doMovement()

execute()

}

}

public void onScannedRobot(ScannedRobotEvent e)

{

enemy.updateStat(e, this)

}

public void doMovement()//随机移动

{ //程序首先判断运动是否完成,若完成,随机选出一个座标点,移动到该点

if( Math.abs( getDistanceRemaining() ) <1 )

{

double myX = getX()

double myY = getY()

double nextX, nextY // the next point move to

nextX = Math.random() * ( getBattleFieldWidth() - 100 ) + 50

nextY = Math.random() * ( getBattleFieldHeight() - 100 ) + 50

double turnAngle =getAngle(myX,myY,nextX,nextY )

turnAngle = normalizeBearing( turnAngle - getHeadingRadians() )

double moveDistance = Point2D.distance( myX, myY, nextX, nextY )

double moveDirection = 1

if ( Math.abs( turnAngle ) >Math.PI/2)

{

turnAngle = normalizeBearing( turnAngle + Math.PI)

moveDirection *= -1

}

setTurnRightRadians( turnAngle )

setAhead( moveDirection * moveDistance )}

}

public static double getAngle(double x1, double y1, double x2, double y2)

{

return Math.atan2( x2 - x1, y2 - y1 )

}

public void doScannedRobot()

{

if (getTime()-enemy.time>1)

{

setTurnRadarRightRadians(3*Math.PI)

}

else

{

double absolation_bearing=(getHeadingRadians()+enemy.relative_bearing)%(2*Math.PI)

double relative_radar_bearing=getRadarHeadingRadians()-absolation_bearing

double a=normalizeBearing(relative_radar_bearing)

setTurnRadarLeftRadians(a)

}

}

public double normalizeBearing( double angle )

{

if ( angle <-Math.PI )

angle += 2*Math.PI

if ( angle >Math.PI )

angle -= 2*Math.PI

return angle

}

public void doFire()

{

double heading_offset=enemy.en_heading-enemy.pre_heading+0.000001

double distance=enemy.distance

double bullet_velocity=20-3*3

double r=enemy.velocity/heading_offset

double heading=0.0

for(int i=0i<4i++)//迭代 使预测更加准确

{

double b_travel_ti=distance/bullet_velocity

double predict_heading_r=enemy.en_heading+heading_offset*b_travel_ti

double predict_x=enemy.xCoordinate-r*Math.cos(predict_heading_r)+r*Math.cos(enemy.en_heading)

double predict_y=enemy.yCoordinate+r*Math.sin(predict_heading_r)-r*Math.sin(enemy.en_heading)

heading=Math.atan2(predict_x-getX(),predict_y-getY())

double diatance=Point2D.distance( getX(), getY(), predict_x, predict_y )

}

double a=normalizeBearing(heading-getGunHeadingRadians())

setTurnGunRightRadians(a)

setFire(3)

}

public void onHitByBullet(HitByBulletEvent e)

{

if(getX()>150&&getY()>150&&enemy.battle_w-getX()>150&&enemy.battle_h-getY()>150)

{

double dist=150

double a=normalizeBearing(90 - (getHeading() - e.getHeading()))

if(Math.abs(a)>Math.PI/2)

{

a=normalizeBearing(a+Math.PI)

}

setTurnRight( a)

setAhead(dist)

dist *= -1

}

}

public void onWin(WinEvent e)

{

for (int i = 0i <50i++)

{

turnGunRightRadians(Math.PI*3/4)

turnGunLeftRadians(Math.PI*3/4)

}

}

}

class enemyStat //方法

{public double pre_heading

public double en_heading

double xCoordinate

double yCoordinate

double direction

double battle_h

double battle_w

double relative_bearing

double velocity

double time

double distance

public void updateStat(ScannedRobotEvent e,AdvancedRobot ar)

{

pre_heading=en_heading

en_heading=e.getHeadingRadians()

battle_h=ar.getBattleFieldHeight()

battle_w=ar.getBattleFieldWidth()

relative_bearing=e.getBearingRadians()

direction = relative_bearing + ar.getHeadingRadians()

xCoordinate= ar.getX() + Math.sin( direction ) * distance

yCoordinate = ar.getY() + Math.cos( direction ) *distance

velocity=e.getVelocity()

time=e.getTime()

distance=e.getDistance()

}

}

一旦你知道自己要做什么,编程就很有趣,但达到这一点,可能是一次痛苦的经历。

这就是为什么在上课、听讲座、看教程之间,你应该留出时间玩一玩编程 游戏 。它们不仅是有趣的放松手段,还能让你亲身实践,这样你会学得更快,记住更多知识。

Robocode

Robocode是个复杂的编程 游戏 ,在这个 游戏 中,你可以编写机器人坦克的代码,让坦克们互相博弈。你要用Java、Scala、C#等编程语言,编写人工智能程序,驱动机器人。

Robocode安装程序附带开发环境,内置机器人编辑器和Java编译器。你写的是真正的代码!尽管Robocode早在2000年就发布了,但它仍然定期更新和维护,因为它是开源的。

Codingame

Codingame是一款类似 游戏 的Web应用程序,通过编写真实代码来解决难题和挑战。支持超过25种编程语言,包括Java、C#、Python、JavaScript、Lua、Go、Rust等。每一个难题或挑战都有一个主题,例如,编程炮塔击落附近的飞艇,是不是很有趣?

Codecombat

Codecombat也是一个用于像 游戏 的谜题挑战类Web应用程序,只能通过编写代码来解决。不过Codengame更有 娱乐 性,Codecombat有很强的教育意义,它有一个“课堂版”,老师可以用来帮助学生学习编码。目前有3种课程可供选择:计算机科学、网络开发和 游戏 开发。

Codewars

Codewars与其说是 游戏 ,不如说是一种练习编码和解决算法挑战的 游戏 化学习方式。解决问题后你可以得到一定点数,点数值取决于你的解决方案的效率。Codewars允许你查看他人提交的解决方案,方便学习和借鉴。

Codehunt

Codehunt是一种可以使用Java或C#来玩的 游戏 。它的目标是教你学会编程语言的基础知识,从训练开始,到循环和字符串等主题,最后是排序、密码和编程难题等挑战。Codehunt的有趣之处在于,它没有告诉你如何赢得每一项挑战。

Vim Adventures

Vim Adventures是一个有趣的类似 游戏 的教程,用于学习如何使用Vim,这是一个功能极其强大的文本编辑器,许多编程专家都喜欢用。然而,它不容易学,这就是为什么有这样的教程。虽然Vim本身不是一种编程语言,但掌握Vim可以帮你更高效地编码。

TIS – 100

TIS - 100是一款与众不同的视频 游戏 ,它迫使你学习并使用模拟的低级汇编代码来解决编程难题。这个 游戏 很难,它是开放式的,只要你没有怒到卸载它,就会发现它的价值。

Shenzhen I/O

Shenzhen I/O 与TIS – 100同属一家工作室的作品,这是一款益智 游戏 ,你的任务是创建简化版电路,并编写电路上运行的简化版汇编代码。与TIS – 100相比,Shenzhen I/O更容易学,更令人愉快,不过也同样复杂。

Human Resource Machine

在Human

Resource

Machine中,你要扮演一名办公室工作人员,通过将各种指令组合在一起来完成任务。从某种意义上来说,这款 游戏 要求通过可视化编程来解决难题,甚至涉及了逻辑流程和内存管理等概念——但以易于理解的、以办公室为主题的方式呈现。这是一个锻炼程序员大脑的好 游戏 。

Screeps

Screeps是一款大型多人在线策略 游戏 ,你要使用JavaScript来编码 游戏 中实体的行为,并为自己建立一个帝国。

学习从来不是一个人的事情,要有个相互监督的伙伴,工作需要学习编程或者为了入行、转行学习编程的伙伴可以私信回复我“学习”领取全套免费编程学习资料、视频

Here are o methods that allow you to remove duplicates in an ArrayList removeDuplicate does not maintain the order where as removeDuplicateWithOrder maintains the order with some performance overheadThe removeDuplicate Method: /** List order not maintained **/ public static void removeDuplicate(ArrayList arlList) {   HashSet h = new HashSet(arlList)  arlList clear()  arlList addAll(h)} The removeDuplicateWithOrder Method: /** List order maintained **/ public static void removeDuplicateWithOrder(ArrayList arlList) {   Set set = new HashSet()  List newList = new ArrayList()  for (Iterator iter = erator()iter hasNext())   {  Object element = iter next() if (set add(element)) newList add(element)  }   arlList clear()  arlList addAll(newList)} lishixinzhi/Article/program/Java/gj/201311/27380


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/11522910.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存