2 shunfurh shunfurh 于 2017.01.10 11:44 提问

Robocode

Description

Robocode is an educational game designed to help learn Java. The players write programs that control tanks fighting with each other on a battlefield. The idea of this game may seem simple, but it takes a lot of effort to write a winning tank's program. Today we are not going to write an intelligent tank, but to design a simplified robocode game engine.

Assuming the whole battlefield is 120*120 (pixel). Each tank can ONLY move in vertical and horizontal direction on the fixed path (There are paths every 10 pixels in the battlefield in both vertical and horizontal direction. In all there are 13 vertical paths and 13 horizontal paths available for tanks, as shown in Figure 1). The shape and size of the tank are negligible and one tank has (x, y) (x, y ∈ [0, 120]) representing its coordinate position and α (α ∈ {0, 90, 180, 270}) representing its facing direction (α = 0, 90, 180 or 270 means facing right, up, left or down respectively). They have a constant speed of 10 pixels/second when they move and they can't move out of the boundary (they will stop moving, staying in the direction that they are currently facing, when touching any boundary of the battlefield). The tank can shoot in the direction it's facing whether it's moving or still. The shot moves at the constant speed 20 pixel/second and the size of the shot is also negligible. It will explode when it meets a tank on the path. It's possible for more than one shot to explode in the same place if they all reach a tank at the exact same time. The tank being hit by the explosion will be destroyed and will be removed from the battlefield at once. A shot exploding or flying out of the boundary will also be removed.

Figure 1

When the game begins, all the tanks are stopped at different crosses of the vertical and horizontal paths. Given the initial information of all the tanks and several commands, your job is to find the winner -- the last living tank when all the commands are executed (or omitted) and no shot exists in the battlefield (meaning that no tank may die in the future).
Input

There are several test cases. The battlefield and paths are all the same for all test cases as shown in Figure 1. Each test case starts with integers N (1 <= N <= 10) and M (1 <= M <= 1000), separated by a blank. N represents the number of the tanks playing in the battlefield, and M represents the number of commands to control the tanks' moving. The following N lines give the initial information (at time 0) of each tank, in the format:
Name x y α

The Name of a tank is consisted of no more than 10 letters. x, y, α are integers and x, y ∈ {0, 10, 20, ..., 120}, α ∈ {0, 90, 180, 270}。Each field is separated by a blank.

The following M lines give commands in such format:
Time Name Content

Each field is separated by a blank. All the commands are giving in the ascending order of Time (0 <= Time <= 30), which is a positive integer meaning the timestamp when the commands are sent. Name points out which tank will receive the command. The Content has different types as follows:
MOVE When receiving the command, the tank starts to move in its facing direction. If the tank is already moving, the command takes no effect.
STOP When receiving the command, the tank stops moving. If the tank is already stopped, the command takes no effect.
TURN angle When receiving the command, the tank changes the facing direction α to be ((α + angle + 360) mod 360), no matter whether it is moving or not. You are guaranteed that ((α + angle + 360) mod 360) ∈ {0, 90, 180, 270}. TURN command doesn't affect the moving state of the tank.
SHOOT When receiving the command, the tank will shoot one shot in the direction it's facing.

Tanks take the corresponding action as soon as they receive the commands. E.g., if the tank at (0, 0), α = 90, receives the command MOVE at time 1, it will start to move at once and will reach (0, 1) at time 2. Notice that a tank could receive multiple commands in one second and take the action one by one. E.g., if the tank at (0, 0), α = 90, receives a command sequence of "TURN 90; SHOOT; TURN -90", it will turn to the direction α = 180, shoot a shot and then turn back. If the tank receives a command sequence of "MOVE; STOP", it will keep still in the original position.

Some more notes you need to pay attention:
If a tank is hit by an explosion, it will take no action to all the commands received at that moment. Of course, all the commands sent to the already destroyed tank should also be omitted.
Although the commands are sent at discrete seconds, the movement and explosions of tanks and shots happen in the continuous time domain.
No two tanks will meet on the path guaranteed by the input data, so you don't need to consider about that situation.
All the input contents will be legal for you.

A test case with N = M = 0 ends the input, and should not be processed.
Output

For each test case, output the winner's name in one line. The winner is defined as the last living tank. If there is no tank or more than one tank living at the end, output "NO WINNER!" in one line.
Sample Input

2 2
A 0 0 90
B 0 120 180
1 A MOVE
2 A SHOOT
2 2
A 0 0 90
B 0 120 270
1 A SHOOT
2 B SHOOT
2 6
A 0 0 90
B 0 120 0
1 A MOVE
2 A SHOOT
6 B MOVE
30 B STOP
30 B TURN 180
30 B SHOOT
0 0
Sample Output

A
NO WINNER!
B

1个回答

caozhy
caozhy   Ds   Rxr 2017.01.15 23:56
已采纳
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
Robocode中一个高效雷达的学习记录
Robocode中一个高效雷达的学习记录还记的刚接触到Robocode的兴奋,为Robocode比赛准备的艰辛,为写出的第一个机器人而高兴万分,为这个丰富的Robocode世界而震撼不已…Robocode入门的门槛很低,但是要提高着实难度不小,这是我研究Robocode以来的一个不错的收获,作为告别Robocode的献礼,也为纪念我研究Robocode的日日夜夜留下点什么东西。本雷达代
在Eclipse下开发Robocode(转)
在Eclipse下开发Robocode(转)2006-07-19 21:30     如果您还不知道什么是Eclipse,请参考这篇文章http://www.loujing.com/Article/ShowArticle.asp?ArticleID=30,或者网上相关资料。    如果您还不知道什么是Robocode,请参考这篇文章http://www.loujing.com/Arti
经典Robocode例子代码--SnippetBot
<!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--><script type="text/javascript"
Robocode Java中使用遗传算法
遗传算法(Genetic Algorithm, GA)是近几年发展起来的一种崭新的全局优化算法。本文将讲解这种算法,并介绍如何 Robocode Java 坦克机器人中采用此算法以实现机器人进化。 遗传算法 遗传算法(Genetic Algorithm, GA)是近几年发展起来的一种崭新的全局优化算法。1962年霍兰德(Holland)教授首次提出了GA算法的思想,它借用了仿真生物遗传学和自然
Robocode&nbsp;&nbsp;入门
在Robocode越来越火爆的今天,仍然有许多人不了解 Robocode是什么,是用来做什么的,怎么使用它。对于这些问题在下文中将详细介绍,本文通俗易懂,让你一看就明白。 什么是Robocode? 有人提议为对学习更多的XP方法学知识感兴趣的开发人员构建一个工作间。把一群人凑到一起,分成小组研究该方法学。然后要有一个经验丰富的XP教练对工作间进行管理,帮助参加者理解其原理。而建议各小组采用的项目就
教你玩Robocode(4)——规则系统
理解Robocode的规则系统,你才能写出更好的坦克。许多规则在Robotcode的Roles类中进行了描述。为了便于大家理解,本文对各种规则参数进行详细叙述。 时间 robocode的时间单位为”轮”(turn)。因此,在描述移动速度时,单位为”像素每轮”(pixels/turn)。“轮”是独立于真实时间的抽象时间单位。游戏速度越快,单位时间内执行的轮数就越多。 在
robocode API中文参考
经典坦克大战实用中文API,包含语法及策略
智能机器人编程游戏robocode的运行代码简析
智能机器人编程游戏robocode的运行代码简析金庆2007.6.1阅读robocode1.3的源代码,查看运行的原理。(转载请注明来源于金庆的专栏)主线程Battle.run()-------------------主线程是Battle.run(), 循环进行多局的较量。每一局初始化后,主要是调用runRound()进行战斗。runRound()内部是一个循环,直到该局结束。    wh
robocode源代码
这个机器人名字是Spectre,在robocode1.6、1.7的环境下能运行,其他的我暂时没尝试。 直接解压缩后就能看到源代码。 所有代码在team.tiny这个包下建立的
Robocode Rumble: 冠军的技巧
Robocode Rumble: 冠军的技巧 Rumble 冠军揭示胜利的机器人背后的策略