Merge branch 'liumingyu_branch' into 'develop'

代码合并



See merge request !6
This commit is contained in:
周浩 2016-08-25 11:15:10 +08:00
commit ade31c7f50
1272 changed files with 145069 additions and 0 deletions

11
代码/workspace_robo4/.gitignore vendored Normal file
View File

@ -0,0 +1,11 @@
.metadata
target
build.xml
maven-build.xml
maven-build.properties
/plugins/dotnet/robocode.dotnet.samples/src/robocode.dotnet.samples.sln
/plugins/dotnet/robocode.dotnet.samples/src/robocode.dotnet.samples.suo
ucdetector_reports
/plugins/dotnet/*.suo
*.class
.recommenders

View File

@ -0,0 +1,12 @@
Robocode
===================
*Build the best - destroy the rest!*
Robocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java or .NET. The robot battles are running in real-time and on-screen.
Read [Introduction] (http://robocode.sourceforge.net/docs/ReadMe.html)
Continue reading on [Robocode home page] (http://robocode.sourceforge.net/)
Learn from community at [RoboWiki] (http://robowiki.net/)
Talk to developers at [robocode-developers] (http://groups.google.com/group/robocode-developers)
Enjoy!

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RemoteSystemsTempFiles</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
<nature>org.eclipse.rse.ui.remoteSystemsTempNature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,17 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@rem NOTE: Here we expect jacobe.exe to be installed on system PATH
@echo off
if exist "%~dp0\tools\lib\jacobe.jar" goto jacobe
call "%~dp0\tools\loadTools.cmd"
:jacobe
call "%~dp0\tools\bin\ant.bat" -buildfile "%~dp0\tools\jacobe\build.xml"

View File

@ -0,0 +1,24 @@
#!/bin/bash
#
# Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://robocode.sourceforge.net/license/epl-v10.html
#
# NOTE: Here we expect the jacobe tools to be installed on PATH
dp0=${0%/*}
if [ ! -f $dp0/tools/lib/ant-launcher.jar ]; then
$dp0/tools/loadTools.sh
elif [ ! -f $dp0/tools/lib/ant.jar ]; then
$dp0/tools/loadTools.sh
elif [ ! -f $dp0/tools/lib/jacobe.jar ]; then
$dp0/tools/loadTools.sh
fi
export CLASSPATH=$CLASSPATH:$dp0/tools/lib/ant-launcher.jar:$dp0/tools/lib/ant.jar:$dp0/tools/lib/jacobe.jar
$dp0/tools/bin/ant.sh -buildfile $dp0/tools/jacobe/build.xml

View File

@ -0,0 +1,15 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@echo off
if not exist "%~dp0\tools\lib\maven-*-uber.jar" (
call "%~dp0\tools\loadTools.cmd"
)
call "%~dp0\tools\bin\mvn.bat" %*

View File

@ -0,0 +1,16 @@
#!/bin/bash
#
# Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://robocode.sourceforge.net/license/epl-v10.html
#
dp0=${0%/*}
if [ ! -f $dp0/tools/lib/maven-*-uber.jar ]; then
$dp0/tools/loadTools.sh
fi
$dp0/tools/bin/mvn.sh $*

View File

@ -0,0 +1,12 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@echo off
mvn clean install ant:ant -DskipTests=false %*
rem mvn eclipse:eclipse

View File

@ -0,0 +1,11 @@
#!/bin/bash
#
# Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
# http://robocode.sourceforge.net/license/epl-v10.html
#
./mvn.sh clean install ant:ant -DskipTests=false $*
#./mvn.sh eclipse:eclipse

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>plugins</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -0,0 +1,88 @@
====
Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://robocode.sourceforge.net/license/epl-v10.html
====
This is guide to build Robocode for .NET
REQUIRED TOOLS FOR BUILDING THE ROBOCODE .NET PLUG-IN
=====================================================
Microsoft C# Compiler and .NET SDK
----------------------------------
- You need C# compiler and .NET SDK at least 4.0:
http://www.microsoft.com/en-us/download/details.aspx?id=17851
- Best option is to install Visual Studio C# Express 2010 or newer.
- NOTE: Make sure you have csc.exe on PATH.
Microsoft HTML Help 1 Compiler and Sandcastle Help File Builder
---------------------------------------------------------------
- 'HTML Help 1 compiler' must be installed on the system - required by the
Sandcastle Help File Builder (SHFB)
HTML Help 1 compiler:
http://msdn.microsoft.com/en-us/library/ms669985(VS.85).aspx
- Sandcastle Help File Builder (SHFB) must be installed on the system.
http://shfb.codeplex.com/
NOTE: When installing the SHFB, you don't need to install HTML Help 2 as
only version 1 is used for Robocode.
Java Development Kit (JDK) and JAVA_HOME path
---------------------------------------------
- Oracle JDK 6 or newer must be installed on the system:
http://www.oracle.com/technetwork/java/javase/downloads
- NOTE: Make sure to install the proper version (32 or 64-bit) depending on the
system.
HOW TO BUILD THE ROBOCODE .NET PLUG-IN
======================================
1) Build the regular part of Robocode first with 'mvn install'
(or mvnassembly.cmd) from source code root directory of Robocode.
2) CD (change directory) to \plugins\dotnet
3) Run: tools\loadTools.cmd
4) Run: tools\keys\gennetkey.cmd
5) Run: mvnassembly.cmd (standing in the \plugins\dotnet directory)
9) Find the resulting distribution file for the Robocode .NET plug-in named
robocode.dotnet-x.x.x.x-setup.jar within this directory:
\plugins\dotnet\robocode.dotnet.distribution\target\
HOW TO BUILD NEW PROXY CLASSES USING JNI4NET
============================================
Robocode uses Jni4net (http://jni4net.com/) to bridge the .NET and Java parts
of Robocode. Only the .NET plug-in is written for the Microsoft .NET platform.
The rest of Robocode is build for the Java platform.
When changing the public APIs or internal classes of Robocode it is important
that the corresponding .NET classes are updated as well. Some classes for the
.NET are handwritten. Other parts are auto-generated using the Jni4Net proxygen
tool (details are provided here: http://jni4net.com/).
In order to update all the auto-generated source files for the .NET plugin you
must:
1) CD (change directory) to \plugins\dotnet
2) Run: generateProxies.cmd
NOTE: You might need to remove the 'rem' and change the following lines inside
the generateProxies.cmd in order to force the JAVA_HOME and PATH to the
correct Java version:
rem set JAVA_HOME=%JDK6_HOME%
rem set PATH=%JAVA_HOME%\bin;%PATH%

View File

@ -0,0 +1,41 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@echo off
rem set JAVA_HOME=%JDK6_HOME%
rem set PATH=%JAVA_HOME%\bin;%PATH%
set NET_FRAMEWORK_HOME=C:\Windows\Microsoft.NET\Framework\v3.5
set PATH=%NET_FRAMEWORK_HOME%;%PATH%
if exist "%~dp0\tools\lib\proxygen.exe" goto gen
call "%~dp0\tools\loadTools.cmd"
:gen
"%~dp0\tools\lib\proxygen.exe" tools\proxygen\robocode.control.proxygen.xml
"%~dp0\tools\lib\proxygen.exe" tools\proxygen\robocode.proxygen.xml
if exist "%~dp0\robocode.dotnet.nhost\target\robocode.dotnet.nhost.dll" goto gen1
echo cat't find robocode.dotnet.nhost\target\robocode.dotnet.nhost.dll, please compile it
goto end
:gen1
if exist "%~dp0\tools\lib\robocode.dll" goto gen3
if exist "%~dp0\robocode.dotnet.api\target\robocode.dll" goto gen2
echo cat't find \robocode.dotnet.api\target\robocode.dll, please compile it
goto end
:gen2
copy "%~dp0\robocode.dotnet.api\target\robocode.dll" "%~dp0\tools\lib"
:gen3
"%~dp0\tools\lib\proxygen.exe" tools\proxygen\robocode.proxygen.net.xml
:end

View File

@ -0,0 +1,20 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@echo off
if not exist "%~dp0\tools\lib" (
mkdir "%~dp0\tools\lib"
call "%~dp0\tools\loadTools.cmd"
)
if not exist "%~dp0\..\..\tools\lib\maven-*-uber.jar" (
call "%~dp0\..\..\tools\loadTools.cmd"
)
call "%~dp0\..\..\mvn" %*

View File

@ -0,0 +1,12 @@
@REM
@REM Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
@REM All rights reserved. This program and the accompanying materials
@REM are made available under the terms of the Eclipse Public License v1.0
@REM which accompanies this distribution, and is available at
@REM http://robocode.sourceforge.net/license/epl-v10.html
@REM
@echo off
mvn clean install ant:ant -DskipTests=false %*
rem mvn eclipse:eclipse

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>robocode.dotnet</artifactId>
<name>.NET Robocode</name>
<version>${robocode.dotnet.version}</version>
<packaging>pom</packaging>
<parent>
<groupId>net.sf.robocode</groupId>
<artifactId>robocode</artifactId>
<version>${robocode.version}</version>
<relativePath>../..</relativePath>
</parent>
<repositories>
<repository>
<id>jni4net.repo</id>
<name>jni4net Repository</name>
<url>http://jni4net.googlecode.com/svn/mvnrepo</url>
</repository>
<repository>
<id>aduna.repo</id>
<name>Aduna Repository</name>
<url>http://repository.aduna-software.org/maven2/</url>
</repository>
</repositories>
<modules>
<module>robocode.dotnet.api</module>
<module>robocode.dotnet.control.api</module>
<module>robocode.dotnet.content</module>
<module>robocode.dotnet.distribution</module>
<module>robocode.dotnet.host</module>
<module>robocode.dotnet.nhost</module>
<module>robocode.dotnet.ntests</module>
<module>robocode.dotnet.robotscs</module>
<module>robocode.dotnet.installer</module>
<module>robocode.dotnet.samples</module>
<module>robocode.dotnet.tests</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonatype.nmaven.plugins</groupId>
<artifactId>maven-dotnet-compiler-plugin</artifactId>
<extensions>true</extensions>
<version>0.17robocode</version>
</plugin>
<plugin>
<groupId>org.sonatype.nmaven.plugins</groupId>
<artifactId>maven-dotnet-test-plugin</artifactId>
<version>0.17robocode</version>
</plugin>
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<version>1.43</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>robocode.dotnet.api</name>
<comment>.NET Robot API for Robocode. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec/>
<natures/>
</projectDescription>

View File

@ -0,0 +1,10 @@
#Tue Nov 27 22:34:10 CET 2012
encoding/src/test/java=8859_1
org.eclipse.jdt.core.compiler.compliance=1.6
encoding/src/main/resources=8859_1
encoding/src/main/java=8859_1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
eclipse.preferences.version=1
encoding/src/test/resources=8859_1
encoding/src=8859_1
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>robocode.dotnet.api</artifactId>
<name>Robocode .NET Robot API</name>
<description>.NET Robot API for Robocode</description>
<packaging>dotnet:library</packaging>
<parent>
<artifactId>robocode.dotnet</artifactId>
<groupId>net.sf.robocode</groupId>
<version>${robocode.dotnet.version}</version>
</parent>
<build>
<finalName>robocode</finalName>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.nmaven.plugins</groupId>
<artifactId>maven-dotnet-compiler-plugin</artifactId>
<configuration>
<aditionalOptions>/unsafe /warn:0 /nowarn:1591 /keyfile:"${basedir}/../tools/keys/robocode.snk"</aditionalOptions>
<finalName>robocode.dll</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
<artifactId>maven-antrun-extended-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<configuration>
<tasks>
<copy file="target/comments.xml" tofile="target/robocode.xml" />
<!--
for this to run, one must have SHFBROOT environment variable set properly.
it comes with installation of SHFB
-->
<exec dir="target" executable="cmd.exe" failonerror="false">
<arg line="/c %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /p:Configuration=Release ../robotAPI.shfbproj" />
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<module version="4" relativePaths="false" type="JAVA_MODULE">
<component name="NewModuleRootManager">
<exclude-output/>
<orderEntry type="inheritedJdk"/>
<!-- output url="file://$$MODULE_DIR$$/${maven.build.dest}"/ -->
<!-- output-test url="file://$$MODULE_DIR$$/${maven.test.dest}"/ -->
<content url="file://$MODULE_DIR$">
<!-- sourceFolder url="file://$$MODULE_DIR$$/${pom.build.sourceDirectory}" isTestSource="false"/ -->
<!-- sourceFolder url="file://$$MODULE_DIR$$/${pom.build.testSourceDirectory}" isTestSource="true"/ -->
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false"/>
<excludeFolder url="file://$MODULE_DIR$/target"/>
</content>
<orderEntry type="sourceFolder" forTests="false"/>
<!-- Next include each dependency:
<orderEntry type="module" module-name="${dep.artifactId}"/>
<orderEntry type="module-library">
<library name="${dep.artifactId}">
<CLASSES>
<root url="jar://${lib.path}!/"/>
</CLASSES>
<JAVADOC/>
<SOURCES/>
</library>
</orderEntry>
-->
<output url="file://$MODULE_DIR$/target/classes"/>
<output-test url="file://$MODULE_DIR$/target/test-classes"/>
</component>
<component name="ModuleRootManager"/>
<!-- If it's a war project:
<component name="WebModuleProperties">
<containerElement type="module" name="${dep.artifactId}">
<attribute name="method" value="1" />
<attribute name="URI" value="/WEB-INF/classes" />
</containerElement>
<containerElement type="library" level="module" name="${dep.artifactId}">
<attribute name="method" value="1" />
<attribute name="URI" value="/WEB-INF/lib/${dep.systemPath.name}" />
</containerElement>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/${pom.build.warSourceDirectory}/WEB-INF/web.xml" version="" />
<webroots>
<root url="file://$MODULE_DIR$/${pom.build.warSourceDirectory}" relative="/" />
</webroots>
</component>
-->
</module>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<!-- The configuration and platform will be used to determine which
assemblies to include from solution and project documentation
sources -->
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{90f0d09b-f58d-4f2e-ac8a-164d89979ef1}</ProjectGuid>
<SHFBSchemaVersion>1.9.5.0</SHFBSchemaVersion>
<!-- AssemblyName, Name, and RootNamespace are not used by SHFB but Visual
Studio adds them anyway -->
<AssemblyName>Documentation</AssemblyName>
<RootNamespace>Documentation</RootNamespace>
<Name>Documentation</Name>
<!-- SHFB properties -->
<OutputPath>.\target\Help\</OutputPath>
<HtmlHelpName>RobotAPI</HtmlHelpName>
<DocumentationSources>
<DocumentationSource sourceFile="target\robocode.dll" xmlns="" />
<DocumentationSource sourceFile="target\robocode.xml" xmlns="" />
</DocumentationSources>
<MissingTags>AutoDocumentCtors, AutoDocumentDispose</MissingTags>
<HelpTitle>Robocode Robot API for .NET</HelpTitle>
<FrameworkVersion>.NET Framework 3.5</FrameworkVersion>
<HelpFileFormat>HtmlHelp1, Website</HelpFileFormat>
<ApiFilter>
<Filter entryType="Namespace" fullName="net.sf.robocode.io" isExposed="False" />
<Filter entryType="Namespace" fullName="net.sf.robocode.nio" isExposed="False" />
<Filter entryType="Namespace" fullName="net.sf.robocode.peer" isExposed="False" />
<Filter entryType="Namespace" fullName="net.sf.robocode.security" isExposed="False" />
<Filter entryType="Namespace" fullName="net.sf.robocode.serialization" isExposed="False" />
<Filter entryType="Namespace" fullName="robocode" isExposed="True">
<Filter entryType="Class" fullName="robocode.Keys" filterName="Keys" isExposed="False" />
</Filter>
<Filter entryType="Namespace" fullName="robocode.exception" isExposed="True">
<Filter entryType="Class" fullName="robocode.exception.EventInterruptedException" filterName="EventInterruptedException" isExposed="False" />
<Filter entryType="Class" fullName="robocode.exception.RobotException" filterName="RobotException" isExposed="False" />
</Filter>
<Filter entryType="Namespace" fullName="System" isExposed="True">
<Filter entryType="Class" fullName="System.Attribute" filterName="Attribute" isExposed="False" />
<Filter entryType="Class" fullName="System.Exception" filterName="Exception" isExposed="False" />
<Filter entryType="Class" fullName="System.Object" filterName="Object" isExposed="False" />
</Filter>
<Filter entryType="Namespace" fullName="System.Security" isExposed="True">
<Filter entryType="Class" fullName="System.Security.CodeAccessPermission" filterName="CodeAccessPermission" isExposed="False" />
</Filter>
<Filter entryType="Namespace" fullName="System.Security.Permissions" isExposed="True">
<Filter entryType="Class" fullName="System.Security.Permissions.SecurityAttribute" filterName="SecurityAttribute" isExposed="False" />
</Filter>
</ApiFilter>
<VisibleItems>InheritedMembers, Protected, SealedProtected</VisibleItems>
<NamespaceSummaries>
<NamespaceSummaryItem name="robocode" isDocumented="True" xmlns="">Robot API used for writing robots for Robocode</NamespaceSummaryItem>
<NamespaceSummaryItem name="robocode.robotinterfaces" isDocumented="True" xmlns="">Robot Interfaces used for creating new robot types, e.g. with other programming languages.</NamespaceSummaryItem>
<NamespaceSummaryItem name="robocode.robotinterfaces.peer" isDocumented="True" xmlns="">Robot peers available for implementing new robot types based on the Robot Interfaces.</NamespaceSummaryItem>
<NamespaceSummaryItem name="robocode.util" isDocumented="True" xmlns="">Utility classes that can be used when writing robots. Kept for compatibility with legacy robots.</NamespaceSummaryItem>
</NamespaceSummaries>
<ProjectSummary>Robocode Robot API for .NET</ProjectSummary>
<CopyrightText>Copyright %28c%29 2001-2016 Mathew A. Nelson and Robocode contributors</CopyrightText>
<FeedbackEMailAddress>fnl%40users.sourceforge.net</FeedbackEMailAddress>
<FeedbackEMailLinkText>administator and maintainer of Robocode</FeedbackEMailLinkText>
<PresentationStyle>vs2010</PresentationStyle>
</PropertyGroup>
<!-- There are no properties for these groups. AnyCPU needs to appear in
order for Visual Studio to perform the build. The others are optional
common platform types that may appear. -->
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|Win32' ">
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Win32' ">
</PropertyGroup>
<!-- Import the SHFB build targets -->
<Import Project="$(SHFBROOT)\SandcastleHelpFileBuilder.targets" />
</Project>

View File

@ -0,0 +1,3 @@
/obj
/robocode.dotnet.api.sln
/robocode.dotnet.api.suo

View File

@ -0,0 +1,12 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using System.Security;
[assembly: AllowPartiallyTrustedCallers]

View File

@ -0,0 +1,132 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.IO;
using System.Security.Permissions;
using System.Text;
using net.sf.robocode.security;
namespace net.sf.robocode.io
{
#pragma warning disable 1591
///<summary>
/// This is a class used for logging.
///</summary>
/// <exclude/>
[RobocodeInternalPermission(SecurityAction.LinkDemand)]
public class LoggerN
{
public static TextWriter realOut = Console.Out;
public static TextWriter realErr = Console.Error;
public static TextWriter robotOut = Console.Out;
private static ILoggerN logListener;
private static readonly StringBuilder logBuffer = new StringBuilder();
[ThreadStatic] public static bool IsSafeThread;
public static void setLogListener(ILoggerN logListener)
{
LoggerN.logListener = logListener;
}
public static void logMessage(string s)
{
logMessage(s, true);
}
public static void logMessage(Exception e)
{
logMessage(e.StackTrace);
}
public static void logMessage(string message, Exception t)
{
logMessage(message + ":\n" + t.StackTrace);
}
public static void logError(string message, Exception t)
{
logError(message + ":\n" + t.StackTrace);
}
public static void logError(Exception t)
{
logError(t.StackTrace);
}
public static void logMessage(string s, bool newline)
{
if (logListener == null)
{
if (newline)
{
realOut.WriteLine(s);
}
else
{
realOut.Write(s);
realOut.Flush();
}
}
else
{
lock (logBuffer)
{
if (!IsSafeThread)
{
// we just queue it, to not let unsafe thread travel thru system
logBuffer.Append(s);
logBuffer.Append("\n");
}
else if (newline)
{
logMessage(logBuffer + s, true);
logBuffer.Length = 0;
}
else
{
logBuffer.Append(s);
}
}
}
}
public static void logError(string s)
{
if (logListener == null)
{
realErr.WriteLine(s);
}
else
{
logListener.logError(s);
}
}
public static void WriteLineToRobotsConsole(string s)
{
if (robotOut != null)
{
robotOut.WriteLine(s);
}
else
{
logMessage(s);
}
}
}
/// <exclude/>
public interface ILoggerN
{
void logMessage(string s, bool newline);
void logError(string s);
}
}
//happy

View File

@ -0,0 +1,508 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

// This class is based on the source code from Sun's Java 1.5.0 API for java.nio.Buffer, but
// rewritten for C# and .NET with the purpose to bridge the .NET and Java internals of Robocode.
using System;
using System.Security.Permissions;
using net.sf.robocode.security;
// ReSharper disable InconsistentNaming
namespace net.sf.robocode.nio
{
#pragma warning disable 1591
#pragma warning disable 1570
/*
* A container for data of a specific primitive type.
*
* <p> A buffer is a linear, finite sequence of elements of a specific
* primitive type. Aside from its content, the essential properties of a
* buffer are its capacity, limit, and position: </p>
*
* <blockquote>
*
* <p> A buffer's <i>capacity</i> is the number of elements it contains. The
* capacity of a buffer is never negative and never changes. </p>
*
* <p> A buffer's <i>limit</i> is the index of the first element that should
* not be read or written. A buffer's limit is never negative and is never
* greater than its capacity. </p>
*
* <p> A buffer's <i>position</i> is the index of the next element to be
* read or written. A buffer's position is never negative and is never
* greater than its limit. </p>
*
* </blockquote>
*
* <p> There is one subclass of this class for each non-boolean primitive type.
*
*
* <h4> Transferring data </h4>
*
* <p> Each subclass of this class defines two categories of <i>get</i> and
* <i>put</i> operations: </p>
*
* <blockquote>
*
* <p> <i>Relative</i> operations read or write one or more elements starting
* at the current position and then increment the position by the number of
* elements transferred. If the requested transfer exceeds the limit then a
* relative <i>get</i> operation throws a {@link BufferUnderflowException}
* and a relative <i>put</i> operation throws a {@link
* BufferOverflowException}; in either case, no data is transferred. </p>
*
* <p> <i>Absolute</i> operations take an explicit element index and do not
* affect the position. Absolute <i>get</i> and <i>put</i> operations throw
* an {@link IndexOutOfBoundsException} if the index argument exceeds the
* limit. </p>
*
* </blockquote>
*
* <p> Data may also, of course, be transferred in to or out of a buffer by the
* I/O operations of an appropriate channel, which are always relative to the
* current position.
*
*
* <h4> Marking and resetting </h4>
*
* <p> A buffer's <i>mark</i> is the index to which its position will be reset
* when the {@link #reset reset} method is invoked. The mark is not always
* defined, but when it is defined it is never negative and is never greater
* than the position. If the mark is defined then it is discarded when the
* position or the limit is adjusted to a value smaller than the mark. If the
* mark is not defined then invoking the {@link #reset reset} method causes an
* {@link InvalidMarkException} to be thrown.
*
*
* <h4> Invariants </h4>
*
* <p> The following invariant holds for the mark, position, limit, and
* capacity values:
*
* <blockquote>
* <tt>0</tt> <tt>&lt;=</tt>
* <i>mark</i> <tt>&lt;=</tt>
* <i>position</i> <tt>&lt;=</tt>
* <i>limit</i> <tt>&lt;=</tt>
* <i>capacity</i>
* </blockquote>
*
* <p> A newly-created buffer always has a position of zero and a mark that is
* undefined. The initial limit may be zero, or it may be some other value
* that depends upon the type of the buffer and the manner in which it is
* constructed. The initial content of a buffer is, in general,
* undefined.
*
*
* <h4> Clearing, flipping, and rewinding </h4>
*
* <p> In addition to methods for accessing the position, limit, and capacity
* values and for marking and resetting, this class also defines the following
* operations upon buffers:
*
* <ul>
*
* <li><p> {@link #clear} makes a buffer ready for a new sequence of
* channel-read or relative <i>put</i> operations: It sets the limit to the
* capacity and the position to zero. </p></li>
*
* <li><p> {@link #flip} makes a buffer ready for a new sequence of
* channel-write or relative <i>get</i> operations: It sets the limit to the
* current position and then sets the position to zero. </p></li>
*
* <li><p> {@link #rewind} makes a buffer ready for re-reading the data that
* it already contains: It leaves the limit unchanged and sets the position
* to zero. </p></li>
*
* </ul>
*
*
* <h4> Read-only buffers </h4>
*
* <p> Every buffer is readable, but not every buffer is writable. The
* mutation methods of each buffer class are specified as <i>optional
* operations</i> that will throw a {@link ReadOnlyBufferException} when
* invoked upon a read-only buffer. A read-only buffer does not allow its
* content to be changed, but its mark, position, and limit values are mutable.
* Whether or not a buffer is read-only may be determined by invoking its
* {@link #isReadOnly isReadOnly} method.
*
*
* <h4> Thread safety </h4>
*
* <p> Buffers are not safe for use by multiple concurrent threads. If a
* buffer is to be used by more than one thread then access to the buffer
* should be controlled by appropriate synchronization.
*
*
* <h4> Invocation chaining </h4>
*
* <p> Methods in this class that do not otherwise have a value to return are
* specified to return the buffer upon which they are invoked. This allows
* method invocations to be chained; for example, the sequence of statements
*
* <blockquote><pre>
* b.flip();
* b.position(23);
* b.limit(42);</pre></blockquote>
*
* can be replaced by the single, more compact statement
*
* <blockquote><pre>
* b.flip().position(23).limit(42);</pre></blockquote>
*
*
* @author Mark Reinhold
* @author JSR-51 Expert Group
* @version 1.35, 06/08/11
* @since 1.4
*/
/// <exclude/>
[RobocodeInternalPermission(SecurityAction.LinkDemand)]
public abstract class Buffer
{
// Invariants: mark <= position <= limit <= capacity
private readonly int _capacity;
private int _limit;
private int _mark = -1;
private int _position;
// Creates a new buffer with the given mark, position, limit, and capacity,
// after checking invariants.
//
protected Buffer(int mark, int pos, int lim, int cap)
{
// package-private
if (cap < 0)
throw new ArgumentException();
_capacity = cap;
limit(lim);
position(pos);
if (mark >= 0)
{
if (mark > pos)
throw new ArgumentException();
_mark = mark;
}
}
/*
* Returns this buffer's capacity. </p>
*
* @return The capacity of this buffer
*/
public int capacity()
{
return _capacity;
}
/*
* Returns this buffer's position. </p>
*
* @return The position of this buffer
*/
public int position()
{
return _position;
}
/*
* Sets this buffer's position. If the mark is defined and larger than the
* new position then it is discarded. </p>
*
* @param newPosition
* The new position value; must be non-negative
* and no larger than the current limit
*
* @return This buffer
*
* @throws ArgumentException
* If the preconditions on <tt>newPosition</tt> do not hold
*/
public Buffer position(int newPosition)
{
if ((newPosition > _limit) || (newPosition < 0))
throw new ArgumentException();
_position = newPosition;
if (_mark > _position) _mark = -1;
return this;
}
/*
* Returns this buffer's limit. </p>
*
* @return The limit of this buffer
*/
public int limit()
{
return _limit;
}
/*
* Sets this buffer's limit. If the position is larger than the new limit
* then it is set to the new limit. If the mark is defined and larger than
* the new limit then it is discarded. </p>
*
* @param newLimit
* The new limit value; must be non-negative
* and no larger than this buffer's capacity
*
* @return This buffer
*
* @throws ArgumentException
* If the preconditions on <tt>newLimit</tt> do not hold
*/
public Buffer limit(int newLimit)
{
if ((newLimit > _capacity) || (newLimit < 0))
throw new ArgumentException();
_limit = newLimit;
if (_position > _limit) _position = _limit;
if (_mark > _limit) _mark = -1;
return this;
}
/*
* Sets this buffer's mark at its position. </p>
*
* @return This buffer
*/
public Buffer mark()
{
_mark = _position;
return this;
}
/*
* Resets this buffer's position to the previously-marked position.
*
* <p> Invoking this method neither changes nor discards the mark's
* value. </p>
*
* @return This buffer
*
* @throws InvalidMarkException
* If the mark has not been set
*/
public Buffer reset()
{
int m = _mark;
if (m < 0)
throw new InvalidMarkException();
_position = m;
return this;
}
/*
* Clears this buffer. The position is set to zero, the limit is set to
* the capacity, and the mark is discarded.
*
* <p> Invoke this method before using a sequence of channel-read or
* <i>put</i> operations to fill this buffer. For example:
*
* <blockquote><pre>
* buf.clear(); // Prepare buffer for reading
* in.read(buf); // Read data</pre></blockquote>
*
* <p> This method does not actually erase the data in the buffer, but it
* is named as if it did because it will most often be used in situations
* in which that might as well be the case. </p>
*
* @return This buffer
*/
public Buffer clear()
{
_position = 0;
_limit = _capacity;
_mark = -1;
return this;
}
/*
* Flips this buffer. The limit is set to the current position and then
* the position is set to zero. If the mark is defined then it is
* discarded.
*
* <p> After a sequence of channel-read or <i>put</i> operations, invoke
* this method to prepare for a sequence of channel-write or relative
* <i>get</i> operations. For example:
*
* <blockquote><pre>
* buf.put(magic); // Prepend header
* in.read(buf); // Read data into rest of buffer
* buf.flip(); // Flip buffer
* out.write(buf); // Write header + data to channel</pre></blockquote>
*
* <p> This method is often used in conjunction with the {@link
* java.nio.ByteBuffer#compact compact} method when transferring data from
* one place to another. </p>
*
* @return This buffer
*/
public Buffer flip()
{
_limit = _position;
_position = 0;
_mark = -1;
return this;
}
/*
* Rewinds this buffer. The position is set to zero and the mark is
* discarded.
*
* <p> Invoke this method before a sequence of channel-write or <i>get</i>
* operations, assuming that the limit has already been set
* appropriately. For example:
*
* <blockquote><pre>
* out.write(buf); // Write remaining data
* buf.rewind(); // Rewind buffer
* buf.get(array); // Copy data into array</pre></blockquote>
*
* @return This buffer
*/
public Buffer rewind()
{
_position = 0;
_mark = -1;
return this;
}
/*
* Returns the number of elements between the current position and the
* limit. </p>
*
* @return The number of elements remaining in this buffer
*/
public int remaining()
{
return _limit - _position;
}
/*
* Tells whether there are any elements between the current position and
* the limit. </p>
*
* @return <tt>true</tt> if, and only if, there is at least one element
* remaining in this buffer
*/
public bool hasRemaining()
{
return _position < _limit;
}
/*
* Tells whether or not this buffer is read-only. </p>
*
* @return <tt>true</tt> if, and only if, this buffer is read-only
*/
public abstract bool isReadOnly();
// -- Package-private methods for bounds checking, etc. --
/*
* Checks the current position against the limit, throwing a {@link
* BufferUnderflowException} if it is not smaller than the limit, and then
* increments the position. </p>
*
* @return The current position value, before it is incremented
*/
internal int nextGetIndex()
{
// package-private
if (_position >= _limit)
throw new BufferUnderflowException();
return _position++;
}
internal int nextGetIndex(int nb)
{
// package-private
if (_limit - _position < nb)
throw new BufferUnderflowException();
int p = _position;
_position += nb;
return p;
}
/*
* Checks the current position against the limit, throwing a {@link
* BufferOverflowException} if it is not smaller than the limit, and then
* increments the position. </p>
*
* @return The current position value, before it is incremented
*/
internal int nextPutIndex()
{
// package-private
if (_position >= _limit)
throw new BufferOverflowException();
return _position++;
}
internal int nextPutIndex(int nb)
{
// package-private
if (_limit - _position < nb)
throw new BufferOverflowException();
int p = _position;
_position += nb;
return p;
}
/*
* Checks the given index against the limit, throwing an {@link
* IndexOutOfBoundsException} if it is not smaller than the limit
* or is smaller than zero.
*/
internal int checkIndex(int i)
{
// package-private
if ((i < 0) || (i >= _limit))
throw new IndexOutOfRangeException();
return i;
}
internal int checkIndex(int i, int nb)
{
// package-private
if ((i < 0) || (nb > _limit - i))
throw new IndexOutOfRangeException();
return i;
}
internal int markValue()
{
// package-private
return _mark;
}
internal void discardMark()
{
// package-private
_mark = -1;
}
internal static void checkBounds(int off, int len, int size)
{
// package-private
if ((off | len | (off + len) | (size - (off + len))) < 0)
throw new IndexOutOfRangeException();
}
}
#pragma warning restore 1591
}
// ReSharper restore InconsistentNaming

View File

@ -0,0 +1,380 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

// This class is based on the source code from Sun's Java 1.5.0 API for java.nio.HeapByteBuffer, but
// rewritten for C# and .NET with the purpose to bridge the .NET and Java internals of Robocode.
using System;
// ReSharper disable InconsistentNaming
namespace net.sf.robocode.nio
{
/// <summary>
/// A read/write HeapByteBuffer.
/// </summary>
/// <exclude/>
internal class HeapByteBuffer : ByteBuffer
{
internal HeapByteBuffer(int cap, int lim)
: base(-1, 0, lim, cap, new byte[cap], 0)
{
}
internal HeapByteBuffer(byte[] buf, int off, int len)
: base(-1, off, off + len, buf.Length, buf, 0)
{
}
protected HeapByteBuffer(byte[] buf,
int mark, int pos, int lim, int cap,
int off)
: base(mark, pos, lim, cap, buf, off)
{
}
public override ByteBuffer slice()
{
return new HeapByteBuffer(hb,
-1,
0,
remaining(),
remaining(),
position() + _offset);
}
public override ByteBuffer duplicate()
{
return new HeapByteBuffer(hb,
markValue(),
position(),
limit(),
capacity(),
_offset);
}
public override ByteBuffer asReadOnlyBuffer()
{
throw new NotImplementedException();
}
protected int ix(int i)
{
return i + _offset;
}
public override byte get()
{
return hb[ix(nextGetIndex())];
}
public override byte get(int i)
{
return hb[ix(checkIndex(i))];
}
public override ByteBuffer get(byte[] dst, int offset, int length)
{
checkBounds(offset, length, dst.Length);
if (length > remaining())
throw new BufferUnderflowException();
Array.Copy(hb, ix(position()), dst, offset, length);
position(position() + length);
return this;
}
public override bool isDirect()
{
return false;
}
public override bool isReadOnly()
{
return false;
}
public override ByteBuffer put(byte x)
{
hb[ix(nextPutIndex())] = x;
return this;
}
public override ByteBuffer put(int i, byte x)
{
hb[ix(checkIndex(i))] = x;
return this;
}
public override ByteBuffer put(byte[] src, int offset, int length)
{
checkBounds(offset, length, src.Length);
if (length > remaining())
throw new BufferOverflowException();
Array.Copy(src, offset, hb, ix(position()), length);
position(position() + length);
return this;
}
public override ByteBuffer put(ByteBuffer src)
{
if (src is HeapByteBuffer)
{
if (src == this)
throw new ArgumentException();
var sb = (HeapByteBuffer) src;
int n = sb.remaining();
if (n > remaining())
throw new BufferOverflowException();
Array.Copy(sb.hb, sb.ix(sb.position()),
hb, ix(position()), n);
sb.position(sb.position() + n);
position(position() + n);
}
else if (src.isDirect())
{
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();
src.get(hb, ix(position()), n);
position(position() + n);
}
else
{
base.put(src);
}
return this;
}
public override ByteBuffer compact()
{
Array.Copy(hb, ix(position()), hb, ix(0), remaining());
position(remaining());
limit(capacity());
discardMark();
return this;
}
internal override byte _get(int i)
{
return hb[i];
}
internal override void _put(int i, byte b)
{
hb[i] = b;
}
public override char getChar()
{
return BitConverter.ToChar(hb, ix(nextGetIndex(2)));
}
public override char getChar(int i)
{
return BitConverter.ToChar(hb, ix(checkIndex(i, 2)));
}
public override ByteBuffer putChar(char x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(2));
Array.Copy(bytes, 0, hb, index, 2);
return this;
}
public override ByteBuffer putChar(int i, char x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 2));
Array.Copy(bytes, 0, hb, index, 2);
return this;
}
public override Buffer asCharBuffer()
{
throw new NotImplementedException();
}
public override short getShort()
{
return BitConverter.ToInt16(hb, ix(nextGetIndex(2)));
}
public override short getShort(int i)
{
return BitConverter.ToInt16(hb, ix(checkIndex(i, 2)));
}
public override ByteBuffer putShort(short x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(2));
Array.Copy(bytes, 0, hb, index, 2);
return this;
}
public override ByteBuffer putShort(int i, short x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 2));
Array.Copy(bytes, 0, hb, index, 2);
return this;
}
public override Buffer asShortBuffer()
{
throw new NotImplementedException();
}
public override int getInt()
{
return BitConverter.ToInt32(hb, ix(nextGetIndex(4)));
}
public override int getInt(int i)
{
return BitConverter.ToInt32(hb, ix(checkIndex(i, 4)));
}
public override ByteBuffer putInt(int x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(4));
Array.Copy(bytes, 0, hb, index, 4);
return this;
}
public override ByteBuffer putInt(int i, int x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 4));
Array.Copy(bytes, 0, hb, index, 4);
return this;
}
public override Buffer asIntBuffer()
{
throw new NotImplementedException();
}
// long
public override long getLong()
{
return BitConverter.ToInt64(hb, ix(nextGetIndex(8)));
}
public override long getLong(int i)
{
return BitConverter.ToInt64(hb, ix(checkIndex(i, 8)));
}
public override ByteBuffer putLong(long x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(8));
Array.Copy(bytes, 0, hb, index, 8);
return this;
}
public override ByteBuffer putLong(int i, long x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 8));
Array.Copy(bytes, 0, hb, index, 8);
return this;
}
public override Buffer asLongBuffer()
{
throw new NotImplementedException();
}
// float
public override float getFloat()
{
return BitConverter.ToSingle(hb, ix(nextGetIndex(4)));
}
public override float getFloat(int i)
{
return BitConverter.ToSingle(hb, ix(checkIndex(i, 4)));
}
public override ByteBuffer putFloat(float x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(4));
Array.Copy(bytes, 0, hb, index, 4);
return this;
}
public override ByteBuffer putFloat(int i, float x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 4));
Array.Copy(bytes, 0, hb, index, 4);
return this;
}
public override Buffer asFloatBuffer()
{
throw new NotImplementedException();
}
// double
public override double getDouble()
{
return BitConverter.ToDouble(hb, ix(nextGetIndex(8)));
}
public override double getDouble(int i)
{
return BitConverter.ToDouble(hb, ix(checkIndex(i, 8)));
}
public override ByteBuffer putDouble(double x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(nextPutIndex(8));
Array.Copy(bytes, 0, hb, index, 8);
return this;
}
public override ByteBuffer putDouble(int i, double x)
{
byte[] bytes = BitConverter.GetBytes(x);
int index = ix(checkIndex(i, 8));
Array.Copy(bytes, 0, hb, index, 8);
return this;
}
public override Buffer asDoubleBuffer()
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,116 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using System;
using System.Runtime.Serialization;
namespace net.sf.robocode.nio
{
#pragma warning disable 1591
/// <exclude/>
[Serializable]
public class InvalidMarkException : Exception
{
public InvalidMarkException()
{
}
public InvalidMarkException(string message)
: base(message)
{
}
public InvalidMarkException(string message, Exception inner)
: base(message, inner)
{
}
protected InvalidMarkException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
/// <exclude/>
[Serializable]
public class BufferUnderflowException : Exception
{
public BufferUnderflowException()
{
}
public BufferUnderflowException(string message)
: base(message)
{
}
public BufferUnderflowException(string message, Exception inner)
: base(message, inner)
{
}
protected BufferUnderflowException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
/// <exclude/>
[Serializable]
public class BufferOverflowException : Exception
{
public BufferOverflowException()
{
}
public BufferOverflowException(string message)
: base(message)
{
}
public BufferOverflowException(string message, Exception inner)
: base(message, inner)
{
}
protected BufferOverflowException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
/// <exclude/>
[Serializable]
public class ReadOnlyBufferException : Exception
{
public ReadOnlyBufferException()
{
}
public ReadOnlyBufferException(string message)
: base(message)
{
}
public ReadOnlyBufferException(string message, Exception inner)
: base(message, inner)
{
}
protected ReadOnlyBufferException(SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
}

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace net.sf.robocode.peer
{
#pragma warning disable 1591
/// <exclude/>
public interface IRobotStaticsN
{
bool IsInteractiveRobot();
bool IsPaintRobot();
bool IsAdvancedRobot();
bool IsTeamRobot();
}
}

View File

@ -0,0 +1,131 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Security.Permissions;
using net.sf.robocode.io;
using net.sf.robocode.peer;
using Robocode;
using Robocode.RobotInterfaces;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
[RobocodeInternalPermission(SecurityAction.LinkDemand)]
public class HiddenAccessN
{
private static IHiddenEventHelper eventHelper;
private static IHiddenBulletHelper bulletHelper;
private static IHiddenStatusHelper statusHelper;
private static IHiddenRulesHelper rulesHelper;
private static bool initialized;
public static IHiddenRandomHelper randomHelper;
public static void init()
{
if (initialized)
{
return;
}
MethodInfo method;
try
{
method = typeof (Event).GetMethod("createHiddenHelper", BindingFlags.Static | BindingFlags.NonPublic);
eventHelper = (IHiddenEventHelper) method.Invoke(null, null);
method = typeof (Bullet).GetMethod("createHiddenHelper", BindingFlags.Static | BindingFlags.NonPublic);
bulletHelper = (IHiddenBulletHelper) method.Invoke(null, null);
method = typeof (RobotStatus).GetMethod("createHiddenSerializer",
BindingFlags.Static | BindingFlags.NonPublic);
statusHelper = (IHiddenStatusHelper) method.Invoke(null, null);
method = typeof (BattleRules).GetMethod("createHiddenHelper",
BindingFlags.Static | BindingFlags.NonPublic);
rulesHelper = (IHiddenRulesHelper) method.Invoke(null, null);
initialized = true;
}
catch (Exception e)
{
LoggerN.logError(e);
Environment.Exit(-1);
}
}
public static bool IsCriticalEvent(Event e)
{
return eventHelper.IsCriticalEvent(e);
}
public static void SetEventTime(Event e, long newTime)
{
eventHelper.SetTime(e, newTime);
}
public static void SetEventPriority(Event e, int newPriority)
{
eventHelper.SetPriority(e, newPriority);
}
public static void Dispatch(Event evnt, IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
eventHelper.Dispatch(evnt, robot, statics, graphics);
}
public static void SetDefaultPriority(Event e)
{
eventHelper.SetDefaultPriority(e);
}
public static byte GetSerializationType(Event e)
{
return eventHelper.GetSerializationType(e);
}
// Needed for .NET version
public static void UpdateBullets(Event e, Dictionary<int, Bullet> bullets)
{
eventHelper.UpdateBullets(e, bullets);
}
public static void Update(Bullet bullet, double x, double y, string victimName, bool isActive)
{
bulletHelper.update(bullet, x, y, victimName, isActive);
}
public static RobotStatus createStatus(double energy, double x, double y, double bodyHeading, double gunHeading,
double radarHeading, double velocity, double bodyTurnRemaining,
double radarTurnRemaining, double gunTurnRemaining,
double distanceRemaining, double gunHeat, int others, int numSentries,
int roundNum, int numRounds, long time)
{
return statusHelper.createStatus(energy, x, y, bodyHeading, gunHeading, radarHeading, velocity,
bodyTurnRemaining, radarTurnRemaining, gunTurnRemaining, distanceRemaining,
gunHeat, others, numSentries, roundNum, numRounds, time);
}
public static BattleRules createRules(int battlefieldWidth, int battlefieldHeight, int numRounds, double gunCoolingRate, long inactivityTime,
bool hideEnemyNames, int borderSentryRobotAttackRange)
{
return rulesHelper.createRules(battlefieldWidth, battlefieldHeight, numRounds, gunCoolingRate, inactivityTime, hideEnemyNames, borderSentryRobotAttackRange);
}
public static string GetRobotName()
{
string name = (string)AppDomain.CurrentDomain.GetData("robotName");
return name ?? "";
}
}
#pragma warning restore 1591
}
//happy

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
public interface IHiddenBulletHelper
{
void update(Bullet bullet, double x, double y, string victimName, bool isActive);
}
}
//happy

View File

@ -0,0 +1,29 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System.Collections.Generic;
using net.sf.robocode.peer;
using Robocode;
using Robocode.RobotInterfaces;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
public interface IHiddenEventHelper
{
void SetDefaultPriority(Event evnt);
void SetPriority(Event evnt, int newPriority);
void SetTime(Event evnt, long newTime);
bool IsCriticalEvent(Event evnt);
void Dispatch(Event evnt, IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics);
byte GetSerializationType(Event evnt);
void UpdateBullets(Event evnt, Dictionary<int, Bullet> bullets); // Needed for .NET version
}
}
//happy

View File

@ -0,0 +1,20 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using System;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
public interface IHiddenRandomHelper
{
Random GetRandom();
}
}

View File

@ -0,0 +1,21 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
public interface IHiddenRulesHelper
{
BattleRules createRules(int battlefieldWidth, int battlefieldHeight, int numRounds, double gunCoolingRate, long inactivityTime,
bool hideEnemyNames, int borderSentryRobotAttackRange);
}
}
//happy

View File

@ -0,0 +1,25 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
public interface IHiddenStatusHelper
{
RobotStatus createStatus(double energy, double x, double y, double bodyHeading, double gunHeading,
double radarHeading,
double velocity, double bodyTurnRemaining, double radarTurnRemaining,
double gunTurnRemaining,
double distanceRemaining, double gunHeat, int others, int numSentries,
int roundNum, int numRounds, long time);
}
}
//happy

View File

@ -0,0 +1,151 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using System;
using System.Security;
using System.Security.Permissions;
using System.Text;
namespace net.sf.robocode.security
{
#pragma warning disable 1591
/// <exclude/>
[Serializable]
public sealed class RobocodeInternalPermission : CodeAccessPermission, IUnrestrictedPermission
{
private bool unrestricted;
public RobocodeInternalPermission(PermissionState state)
{
unrestricted = state == PermissionState.Unrestricted;
}
#region IUnrestrictedPermission Members
public bool IsUnrestricted()
{
return unrestricted;
}
#endregion
public override IPermission Copy()
{
//Create a new instance of RobocodeInternalPermission with the current
//value of unrestricted.
var copy = new RobocodeInternalPermission(PermissionState.None);
copy.unrestricted = IsUnrestricted();
//Return the copy.
return copy;
}
public override IPermission Intersect(IPermission target)
{
//If nothing was passed, return null.
if (null == target)
{
return null;
}
try
{
//Create a new instance of RobocodeInternalPermission from the passed object.
var PassedPermission = (RobocodeInternalPermission) target;
//If one class has an unrestricted value of false, then the
//intersection will have an unrestricted value of false.
//Return the passed class with the unrestricted value of false.
if (!PassedPermission.unrestricted)
{
return target;
}
//Return a copy of the current class if the passed one has
//an unrestricted value of true.
return Copy();
}
//Catch an InvalidCastException.
//Throw ArgumentException to notify the user.
catch (InvalidCastException)
{
throw new ArgumentException("Argument_WrongType", GetType().FullName);
}
}
public override bool IsSubsetOf(IPermission target)
{
//If nothing was passed and unrestricted is false,
//then return true.
if (null == target)
{
return !unrestricted;
}
try
{
//Create a new instance of RobocodeInternalPermission from the passed object.
var passedpermission = (RobocodeInternalPermission) target;
//If unrestricted has the same value in both objects, then
//one is the subset of the other.
return unrestricted == passedpermission.unrestricted;
}
//Catch an InvalidCastException.
//Throw ArgumentException to notify the user.
catch (InvalidCastException)
{
throw new ArgumentException("Argument_WrongType", GetType().FullName);
}
}
public override void FromXml(SecurityElement PassedElement)
{
//Get the unrestricted value from the XML and initialize
//the current instance of unrestricted to that value.
string element = PassedElement.Attribute("Unrestricted");
if (null != element)
{
unrestricted = Convert.ToBoolean(element);
}
}
public override SecurityElement ToXml()
{
//Encode the current permission to XML using the
//SecurityElement class.
var element = new SecurityElement("IPermission");
Type type = GetType();
var AssemblyName = new StringBuilder(type.Assembly.ToString());
AssemblyName.Replace('\"', '\'');
element.AddAttribute("class", type.FullName + ", " + AssemblyName);
element.AddAttribute("version", "1");
element.AddAttribute("Unrestricted", unrestricted.ToString());
return element;
}
}
/// <exclude/>
[AttributeUsageAttribute(AttributeTargets.All, AllowMultiple = true)]
public class RobocodeInternalPermissionAttribute : CodeAccessSecurityAttribute
{
public RobocodeInternalPermissionAttribute(SecurityAction action)
: base(action)
{
Unrestricted = false;
}
public override IPermission CreatePermission()
{
return Unrestricted
? new RobocodeInternalPermission(PermissionState.Unrestricted)
: new RobocodeInternalPermission(PermissionState.None);
}
}
#pragma warning restore 1591
}

View File

@ -0,0 +1,22 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using net.sf.robocode.nio;
namespace net.sf.robocode.serialization
{
#pragma warning disable 1591
/// <exclude/>
public interface ISerializableHelperN
{
int sizeOf(RbSerializerN serializer, object obj);
void serialize(RbSerializerN serializer, ByteBuffer buffer, object obj);
object deserialize(RbSerializerN serializer, ByteBuffer buffer);
}
}
//happy

View File

@ -0,0 +1,524 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Security.Permissions;
using System.Text;
using net.sf.robocode.io;
using net.sf.robocode.nio;
using net.sf.robocode.security;
using Robocode;
namespace net.sf.robocode.serialization
{
#pragma warning disable 1591
/// <exclude/>
[RobocodeInternalPermission(SecurityAction.LinkDemand)]
public sealed class RbSerializerN
{
private const int byteOrder = -1059135839; //0xC0DEDEA1
public static readonly int SIZEOF_TYPEINFO = 1;
public static readonly int SIZEOF_BYTE = 1;
public static readonly int SIZEOF_BOOL = 1;
public static readonly int SIZEOF_CHAR = 2;
public static readonly int SIZEOF_INT = 4;
public static readonly int SIZEOF_LONG = 8;
public static readonly int SIZEOF_DOUBLE = 8;
public static readonly byte TERMINATOR_TYPE = 0xff;
public static readonly byte ExecCommands_TYPE = 1;
public static readonly byte BulletCommand_TYPE = 2;
public static readonly byte TeamMessage_TYPE = 3;
public static readonly byte DebugProperty_TYPE = 4;
public static readonly byte ExecResults_TYPE = 5;
public static readonly byte RobotStatus_TYPE = 6;
public static readonly byte BulletStatus_TYPE = 7;
public static readonly byte BattleResults_TYPE = 8;
public static readonly byte Bullet_TYPE = 9;
public static readonly byte RobotStatics_TYPE = 10;
public static readonly byte BattleEndedEvent_TYPE = 32;
public static readonly byte BulletHitBulletEvent_TYPE = 33;
public static readonly byte BulletHitEvent_TYPE = 34;
public static readonly byte BulletMissedEvent_TYPE = 35;
public static readonly byte DeathEvent_TYPE = 36;
public static readonly byte WinEvent_TYPE = 37;
public static readonly byte HitWallEvent_TYPE = 38;
public static readonly byte RobotDeathEvent_TYPE = 39;
public static readonly byte SkippedTurnEvent_TYPE = 40;
public static readonly byte ScannedRobotEvent_TYPE = 41;
public static readonly byte HitByBulletEvent_TYPE = 42;
public static readonly byte HitRobotEvent_TYPE = 43;
public static readonly byte KeyPressedEvent_TYPE = 44;
public static readonly byte KeyReleasedEvent_TYPE = 45;
public static readonly byte KeyTypedEvent_TYPE = 46;
public static readonly byte MouseClickedEvent_TYPE = 47;
public static readonly byte MouseDraggedEvent_TYPE = 48;
public static readonly byte MouseEnteredEvent_TYPE = 49;
public static readonly byte MouseExitedEvent_TYPE = 50;
public static readonly byte MouseMovedEvent_TYPE = 51;
public static readonly byte MousePressedEvent_TYPE = 52;
public static readonly byte MouseReleasedEvent_TYPE = 53;
public static readonly byte MouseWheelMovedEvent_TYPE = 54;
public static readonly byte RoundEndedEvent_TYPE = 55;
private static readonly ISerializableHelperN[] typeToHelper = new ISerializableHelperN[256];
private static readonly Dictionary<Type, byte> classToType = new Dictionary<Type, byte>();
private static readonly Encoding charset;
private static int currentVersion;
static RbSerializerN()
{
charset = Encoding.UTF8; // we will use it as UCS-2
register(null, TERMINATOR_TYPE); // reserved for end of (list) element
}
public static void Init(int version)
{
if (currentVersion == 0)
{
currentVersion = version;
}
}
public ByteBuffer serialize(byte type, object obj)
{
int length = sizeOf(type, obj);
// header
ByteBuffer buffer = ByteBuffer.allocate(SIZEOF_INT + SIZEOF_INT + SIZEOF_INT + length);
buffer.putInt(byteOrder);
buffer.putInt(currentVersion);
buffer.putInt(length);
// body
serialize(buffer, type, obj);
if (buffer.remaining() != 0)
{
throw new IOException("Serialization failed: bad size");
}
return buffer;
}
public ByteBuffer serializeToBuffer(ByteBuffer buffer, byte type, object obj)
{
int length = sizeOf(type, obj);
buffer.limit(SIZEOF_INT + SIZEOF_INT + SIZEOF_INT + length);
buffer.putInt(byteOrder);
buffer.putInt(currentVersion);
buffer.putInt(length);
// body
serialize(buffer, type, obj);
if (buffer.remaining() != 0)
{
throw new IOException("Serialization failed: bad size");
}
return buffer;
}
public Object deserialize(ByteBuffer buffer)
{
int bo = buffer.getInt();
if (bo != byteOrder)
{
throw new IOException("Different byte order is not supported");
}
int version = buffer.getInt();
if (version != currentVersion)
{
throw new IOException("Version of data is not supported. We support only strong match");
}
int length = buffer.getInt();
if (length != buffer.remaining())
{
throw new IOException("Wrong buffer size, " + length + "expected but got " + buffer.remaining());
}
// body
Object res = deserializeAny(buffer);
if (buffer.remaining() != 0)
{
throw new IOException("Serialization failed");
}
return res;
}
public void serialize(ByteBuffer buffer, byte type, object obj)
{
ISerializableHelperN helper = getHelper(type);
// FOR-DEBUG int expect = sizeOf(type, object) + buffer.position();
if (obj != null)
{
buffer.put(type);
helper.serialize(this, buffer, obj);
}
else
{
buffer.put(TERMINATOR_TYPE);
}
// FOR-DEBUG if (expect != buffer.position()) {
// FOR-DEBUG throw new Exception("Bad size");
// FOR-DEBUG }
}
public void serialize(ByteBuffer buffer, string data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
int bytes = charset.GetBytes(data, 0, data.Length, buffer.array(), buffer.position() + 4);
buffer.putInt(bytes);
buffer.position(buffer.position() + bytes);
}
}
public void serialize(ByteBuffer buffer, byte[] data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
buffer.putInt(data.Length);
buffer.put(data);
}
}
public void serialize(ByteBuffer buffer, int[] data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
buffer.putInt(data.Length);
foreach (int aData in data)
{
buffer.putInt(aData);
}
}
}
public void serialize(ByteBuffer buffer, char[] data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
buffer.putInt(data.Length);
foreach (char aData in data)
{
buffer.putChar(aData);
}
}
}
public void serialize(ByteBuffer buffer, double[] data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
buffer.putInt(data.Length);
foreach (double aData in data)
{
buffer.putDouble(aData);
}
}
}
public void serialize(ByteBuffer buffer, float[] data)
{
if (data == null)
{
buffer.putInt(-1);
}
else
{
buffer.putInt(data.Length);
foreach (float aData in data)
{
buffer.putFloat(aData);
}
}
}
public void serialize(ByteBuffer buffer, bool value)
{
buffer.put((byte) (value ? 1 : 0));
}
public void serialize(ByteBuffer buffer, double value)
{
buffer.putDouble(value);
}
public void serialize(ByteBuffer buffer, char value)
{
buffer.putChar(value);
}
public void serialize(ByteBuffer buffer, long value)
{
buffer.putLong(value);
}
public void serialize(ByteBuffer buffer, int value)
{
buffer.putInt(value);
}
public void serialize(ByteBuffer buffer, Event evnt)
{
byte type = HiddenAccessN.GetSerializationType(evnt);
serialize(buffer, type, evnt);
}
public Object deserializeAny(ByteBuffer buffer)
{
byte type = buffer.get();
if (type == TERMINATOR_TYPE)
{
return null;
}
return getHelper(type).deserialize(this, buffer);
}
public string deserializeString(ByteBuffer buffer)
{
int bytes = buffer.getInt();
if (bytes == -1)
{
return null;
}
ByteBuffer slice = buffer.slice();
slice.limit(bytes);
string res;
try
{
byte[] array = buffer.array();
char[] chars = charset.GetChars(array, buffer.position(), bytes);
res = new string(chars);
}
catch (Exception e)
{
throw new Exception("Bad character", e);
}
buffer.position(buffer.position() + bytes);
return res;
}
public byte[] deserializeBytes(ByteBuffer buffer)
{
int len = buffer.getInt();
if (len == -1)
{
return null;
}
var res = new byte[len];
buffer.get(res);
return res;
}
public int[] deserializeints(ByteBuffer buffer)
{
int len = buffer.getInt();
if (len == -1)
{
return null;
}
var res = new int[len];
for (int i = 0; i < len; i++)
{
res[i] = buffer.getInt();
}
return res;
}
public float[] deserializeFloats(ByteBuffer buffer)
{
int len = buffer.getInt();
if (len == -1)
{
return null;
}
var res = new float[len];
for (int i = 0; i < len; i++)
{
res[i] = buffer.getFloat();
}
return res;
}
public char[] deserializeChars(ByteBuffer buffer)
{
int len = buffer.getInt();
if (len == -1)
{
return null;
}
var res = new char[len];
for (int i = 0; i < len; i++)
{
res[i] = buffer.getChar();
}
return res;
}
public double[] deserializeDoubles(ByteBuffer buffer)
{
int len = buffer.getInt();
if (len == -1)
{
return null;
}
var res = new double[len];
for (int i = 0; i < len; i++)
{
res[i] = buffer.getDouble();
}
return res;
}
public bool deserializeBoolean(ByteBuffer buffer)
{
return buffer.get() != 0;
}
public char deserializeChar(ByteBuffer buffer)
{
return buffer.getChar();
}
public int deserializeInt(ByteBuffer buffer)
{
return buffer.getInt();
}
public long deserializeLong(ByteBuffer buffer)
{
return buffer.getLong();
}
public float deserializeFloat(ByteBuffer buffer)
{
return buffer.getFloat();
}
public double deserializeDouble(ByteBuffer buffer)
{
return buffer.getDouble();
}
public int sizeOf(string data)
{
return (data == null) ? SIZEOF_INT : SIZEOF_INT + charset.GetByteCount(data);
}
public int sizeOf(byte[] data)
{
return (data == null) ? SIZEOF_INT : SIZEOF_INT + data.Length;
}
public int sizeOf(byte type, object obj)
{
return getHelper(type).sizeOf(this, obj);
}
public int sizeOf(Event evnt)
{
return sizeOf(HiddenAccessN.GetSerializationType(evnt), evnt);
}
private static ISerializableHelperN getHelper(byte type)
{
ISerializableHelperN helper = typeToHelper[type];
if (helper == null)
{
throw new Exception("Unknownd or unsupported data type");
}
return helper;
}
public static void register(Type realClass, byte type)
{
try
{
if (realClass != null)
{
MethodInfo method = realClass.GetMethod("createHiddenSerializer",
BindingFlags.NonPublic | BindingFlags.Static);
var helper = (ISerializableHelperN) method.Invoke(null, null);
typeToHelper[type] = helper;
classToType.Add(realClass, type);
}
}
catch (Exception e)
{
LoggerN.logError(e);
}
}
public static ByteBuffer serializeToBuffer(Object src)
{
var rbs = new RbSerializerN();
Byte type = classToType[src.GetType()];
return rbs.serialize(type, src);
}
public static T deserializeFromBuffer<T>(ByteBuffer buffer)
{
var rbs = new RbSerializerN();
Object res = rbs.deserialize(buffer);
return (T) res;
}
}
}
//happy

View File

@ -0,0 +1,164 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7E0900D3-6E8F-48EB-86DB-AA767AA90B84}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>robocode</RootNamespace>
<AssemblyName>robocode</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\tools\keys\robocode.snk</AssemblyOriginatorKeyFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\target\</OutputPath>
<IntermediateOutputPath>..\target\obj\</IntermediateOutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>..\target\robocode.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\target\</OutputPath>
<IntermediateOutputPath>..\target\obj\</IntermediateOutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<Compile Include="..\target\build-sources\generated-sources\META-INF\AssemblyInfo.cs">
<Link>AssemblyInfo.cs</Link>
</Compile>
<Compile Include="AssemblyInf.cs" />
<Compile Include="net\sf\robocode\io\LoggerN.cs" />
<Compile Include="net\sf\robocode\peer\IRobotStaticsN.cs" />
<Compile Include="net\sf\robocode\security\HiddenAccessN.cs" />
<Compile Include="net\sf\robocode\security\IHiddenBulletHelper.cs" />
<Compile Include="net\sf\robocode\security\IHiddenEventHelper.cs" />
<Compile Include="net\sf\robocode\security\IHiddenRandomHelper.cs" />
<Compile Include="net\sf\robocode\security\IHiddenRulesHelper.cs" />
<Compile Include="net\sf\robocode\security\IHiddenStatusHelper.cs" />
<Compile Include="net\sf\robocode\security\RobocodeInternalPermission.cs" />
<Compile Include="net\sf\robocode\serialization\ISerializableHelperN.cs" />
<Compile Include="net\sf\robocode\serialization\RbSerializerN.cs" />
<Compile Include="net\sf\robocode\nio\Buffer.cs" />
<Compile Include="net\sf\robocode\nio\ByteBuffer.cs" />
<Compile Include="net\sf\robocode\nio\HeapByteBuffer.cs" />
<Compile Include="net\sf\robocode\nio\InvalidMarkException.cs" />
<Compile Include="robocode\AdvancedRobot.cs" />
<Compile Include="robocode\BattleEndedEvent.cs" />
<Compile Include="robocode\BattleResults.cs" />
<Compile Include="robocode\BattleRules.cs" />
<Compile Include="robocode\Bullet.cs" />
<Compile Include="robocode\BulletHitBulletEvent.cs" />
<Compile Include="robocode\BulletHitEvent.cs" />
<Compile Include="robocode\BulletMissedEvent.cs" />
<Compile Include="robocode\Condition.cs" />
<Compile Include="robocode\IBorderSentry.cs" />
<Compile Include="robocode\CustomEvent.cs" />
<Compile Include="robocode\DeathEvent.cs" />
<Compile Include="robocode\IDroid.cs" />
<Compile Include="robocode\Event.cs" />
<Compile Include="robocode\exception\EventInterruptedException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="robocode\exception\RobotException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="robocode\IGraphics.cs" />
<Compile Include="robocode\GunTurnCompleteCondition.cs" />
<Compile Include="robocode\HitByBulletEvent.cs" />
<Compile Include="robocode\HitRobotEvent.cs" />
<Compile Include="robocode\HitWallEvent.cs" />
<Compile Include="robocode\JuniorRobot.cs" />
<Compile Include="robocode\KeyEvent.cs" />
<Compile Include="robocode\KeyPressedEvent.cs" />
<Compile Include="robocode\KeyReleasedEvent.cs" />
<Compile Include="robocode\Keys.cs" />
<Compile Include="robocode\KeyTypedEvent.cs" />
<Compile Include="robocode\MessageEvent.cs" />
<Compile Include="robocode\MouseClickedEvent.cs" />
<Compile Include="robocode\MouseDraggedEvent.cs" />
<Compile Include="robocode\MouseEnteredEvent.cs" />
<Compile Include="robocode\MouseEvent.cs" />
<Compile Include="robocode\MouseExitedEvent.cs" />
<Compile Include="robocode\MouseMovedEvent.cs" />
<Compile Include="robocode\MousePressedEvent.cs" />
<Compile Include="robocode\MouseReleasedEvent.cs" />
<Compile Include="robocode\MouseWheelMovedEvent.cs" />
<Compile Include="robocode\MoveCompleteCondition.cs" />
<Compile Include="robocode\PaintEvent.cs" />
<Compile Include="robocode\RadarTurnCompleteCondition.cs" />
<Compile Include="robocode\RateControlRobot.cs" />
<Compile Include="robocode\Robot.cs" />
<Compile Include="robocode\RobotDeathEvent.cs" />
<Compile Include="robocode\robotinterfaces\IAdvancedEvents.cs" />
<Compile Include="robocode\robotinterfaces\IAdvancedRobot.cs" />
<Compile Include="robocode\robotinterfaces\IBasicEvents.cs" />
<Compile Include="robocode\robotinterfaces\IBasicEvents2.cs" />
<Compile Include="robocode\robotinterfaces\IBasicEvents3.cs" />
<Compile Include="robocode\robotinterfaces\IBasicRobot.cs" />
<Compile Include="robocode\robotinterfaces\IInteractiveEvents.cs" />
<Compile Include="robocode\robotinterfaces\IInteractiveRobot.cs" />
<Compile Include="robocode\robotinterfaces\IJuniorRobot.cs" />
<Compile Include="robocode\robotinterfaces\IPaintEvents.cs" />
<Compile Include="robocode\robotinterfaces\IPaintRobot.cs" />
<Compile Include="robocode\robotinterfaces\ITeamEvents.cs" />
<Compile Include="robocode\robotinterfaces\ITeamRobot.cs" />
<Compile Include="robocode\robotinterfaces\peer\IAdvancedRobotPeer.cs" />
<Compile Include="robocode\robotinterfaces\peer\IBasicRobotPeer.cs" />
<Compile Include="robocode\robotinterfaces\peer\IJuniorRobotPeer.cs" />
<Compile Include="robocode\robotinterfaces\peer\IStandardRobotPeer.cs" />
<Compile Include="robocode\robotinterfaces\peer\ITeamRobotPeer.cs" />
<Compile Include="robocode\robotinterfaces\IRunnable.cs" />
<Compile Include="robocode\RobotStatus.cs" />
<Compile Include="robocode\RoundEndedEvent.cs" />
<Compile Include="robocode\Rules.cs" />
<Compile Include="robocode\Thread.cs" />
<Compile Include="robocode\ScannedRobotEvent.cs" />
<Compile Include="robocode\SkippedTurnEvent.cs" />
<Compile Include="robocode\StatusEvent.cs" />
<Compile Include="robocode\TeamRobot.cs" />
<Compile Include="robocode\TurnCompleteCondition.cs" />
<Compile Include="robocode\util\Utils.cs" />
<Compile Include="robocode\WinEvent.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>copy "$(TargetPath)" "$(SolutionDir)\robocode.dotnet.host\target"</PostBuildEvent>
<PreBuildEvent>if not exist $(OutDir)\build-sources\generated-sources\META-INF mkdir $(OutDir)\build-sources\generated-sources\META-INF\
echo [assembly: System.Reflection.AssemblyVersion("1.9.2.4")] &gt; $(OutDir)\build-sources\generated-sources\META-INF\AssemblyInfo.cs
</PreBuildEvent>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,126 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
///<summary>
/// A BattleEndedEvent is sent to <see cref="Robot.OnBattleEnded(BattleEndedEvent)"/>
/// when the battle is ended.
/// You can use the information contained in this event to determine if the
/// battle was aborted and also get the results of the battle.
/// <seealso cref="BattleResults"/>
/// <seealso cref="Robot.OnBattleEnded(BattleEndedEvent)"/>
///</summary>
[Serializable]
public sealed class BattleEndedEvent : Event
{
private const int DEFAULT_PRIORITY = 100; // System event -> cannot be changed!;
private readonly bool aborted;
private readonly BattleResults results;
///
///<summary>
/// Called by the game to create a new BattleEndedEvent.
///</summary>
public BattleEndedEvent(bool aborted, BattleResults results)
{
this.aborted = aborted;
this.results = results;
}
///<summary>
/// Checks if this battle was aborted.
/// Returns true if the battle was aborted
///</summary>
public bool IsAborted
{
get { return aborted; }
}
///<summary>
/// Returns the battle results.
///</summary>
public BattleResults Results
{
get { return results; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
/// <inheritdoc />
public override int Priority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (robot != null)
{
var listener = robot.GetBasicEventListener() as IBasicEvents2;
if (listener != null)
{
listener.OnBattleEnded(this);
}
}
}
internal override bool IsCriticalEvent
{
get { return true; }
}
internal override byte SerializationType
{
get { return RbSerializerN.BattleEndedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (BattleEndedEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_BOOL
+ serializer.sizeOf(RbSerializerN.BattleResults_TYPE, obj.results);
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (BattleEndedEvent) objec;
serializer.serialize(buffer, obj.aborted);
serializer.serialize(buffer, RbSerializerN.BattleResults_TYPE, obj.results);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
bool aborted = serializer.deserializeBoolean(buffer);
var results = (BattleResults) serializer.deserializeAny(buffer);
return new BattleEndedEvent(aborted, results);
}
}
}
}
//docl

View File

@ -0,0 +1,225 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.serialization;
namespace Robocode
{
///<summary>
/// Contains the battle results returned by <see cref="BattleEndedEvent.Results"/>
/// when a battle has ended.
/// <seealso cref="BattleEndedEvent.Results"/>
/// <seealso cref="Robot.OnBattleEnded(BattleEndedEvent)"/>
///</summary>
[Serializable]
public class BattleResults : IComparable<BattleResults>
{
internal string teamLeaderName;
internal int rank;
internal double score;
internal double survival;
internal double lastSurvivorBonus;
internal double bulletDamage;
internal double bulletDamageBonus;
internal double ramDamage;
internal double ramDamageBonus;
internal int firsts;
internal int seconds;
internal int thirds;
///<summary>
/// Constructs this BattleResults object.
///</summary>
public BattleResults(
string teamLeaderName,
int rank,
double score,
double survival,
double lastSurvivorBonus,
double bulletDamage,
double bulletDamageBonus,
double ramDamage,
double ramDamageBonus,
int firsts,
int seconds,
int thirds
)
{
this.teamLeaderName = teamLeaderName;
this.rank = rank;
this.score = score;
this.survival = survival;
this.lastSurvivorBonus = lastSurvivorBonus;
this.bulletDamage = bulletDamage;
this.bulletDamageBonus = bulletDamageBonus;
this.ramDamage = ramDamage;
this.ramDamageBonus = ramDamageBonus;
this.firsts = firsts;
this.seconds = seconds;
this.thirds = thirds;
}
///<summary>
/// Returns the name of the team leader in the team or the name of the
/// robot if the robot is not participating in a team.
///</summary>
public string TeamLeaderName
{
get { return teamLeaderName; }
}
///<summary>
/// Returns the rank of this robot in the battle results.
///</summary>
public int Rank
{
get { return rank; }
}
///<summary>
/// Returns the total score of this robot in the battle.
///</summary>
public int Score
{
get { return (int) (score + 0.5); }
}
///<summary>
/// Returns the survival score of this robot in the battle.
///</summary>
public int Survival
{
get { return (int) (survival + 0.5); }
}
///<summary>
/// Returns the last survivor score of this robot in the battle.
///</summary>
public int LastSurvivorBonus
{
get { return (int) (lastSurvivorBonus + 0.5); }
}
///<summary>
/// Returns the bullet damage score of this robot in the battle.
///</summary>
public int BulletDamage
{
get { return (int) (bulletDamage + 0.5); }
}
///<summary>
/// Returns the bullet damage bonus of this robot in the battle.
///</summary>
public int BulletDamageBonus
{
get { return (int) (bulletDamageBonus + 0.5); }
}
///<summary>
/// Returns the ram damage score of this robot in the battle.
///</summary>
public int RamDamage
{
get { return (int) (ramDamage + 0.5); }
}
///<summary>
/// Returns the ram damage bonus of this robot in the battle.
///</summary>
public int RamDamageBonus
{
get { return (int) (ramDamageBonus + 0.5); }
}
///<summary>
/// Returns the number of rounds this robot placed first in the battle.
///</summary>
public int Firsts
{
get { return firsts; }
}
///<summary>
/// Returns the number of rounds this robot placed second in the battle.
///</summary>
public int Seconds
{
get { return seconds; }
}
///<summary>
/// Returns the number of rounds this robot placed third in the battle.
///</summary>
public int Thirds
{
get { return thirds; }
}
public int CompareTo(BattleResults o)
{
return score.CompareTo(o.score);
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (BattleResults) objec;
return RbSerializerN.SIZEOF_TYPEINFO + serializer.sizeOf(obj.teamLeaderName) +
4*RbSerializerN.SIZEOF_INT
+ 7*RbSerializerN.SIZEOF_DOUBLE;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (BattleResults) objec;
serializer.serialize(buffer, obj.teamLeaderName);
serializer.serialize(buffer, obj.rank);
serializer.serialize(buffer, obj.score);
serializer.serialize(buffer, obj.survival);
serializer.serialize(buffer, obj.lastSurvivorBonus);
serializer.serialize(buffer, obj.bulletDamage);
serializer.serialize(buffer, obj.bulletDamageBonus);
serializer.serialize(buffer, obj.ramDamage);
serializer.serialize(buffer, obj.ramDamageBonus);
serializer.serialize(buffer, obj.firsts);
serializer.serialize(buffer, obj.seconds);
serializer.serialize(buffer, obj.thirds);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
string teamLeaderName = serializer.deserializeString(buffer);
int rank = buffer.getInt();
double score = buffer.getDouble();
double survival = buffer.getDouble();
double lastSurvivorBonus = buffer.getDouble();
double bulletDamage = buffer.getDouble();
double bulletDamageBonus = buffer.getDouble();
double ramDamage = buffer.getDouble();
double ramDamageBonus = buffer.getDouble();
int firsts = buffer.getInt();
int seconds = buffer.getInt();
int thirds = buffer.getInt();
return new BattleResults(teamLeaderName, rank, score, survival, lastSurvivorBonus, bulletDamage,
bulletDamageBonus, ramDamage, ramDamageBonus, firsts, seconds, thirds);
}
}
}
}
//doc

View File

@ -0,0 +1,137 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.security;
namespace Robocode
{
/// <summary>
/// Contains the battle rules returned by <see cref="Robocode.Control.Events.BattleStartedEvent.BattleRules">BattleStartedEvent.BattleRules</see>
/// when a battle is started and <see cref="Robocode.Control.Events.BattleCompletedEvent.BattleRules">BattleCompletedEvent.BattleRules</see>
/// when a battle is completed.
/// </summary>
/// <seealso cref="Robocode.Control.Events.BattleStartedEvent">BattleStartedEvent</seealso>
/// <seealso cref="Robocode.Control.Events.BattleCompletedEvent">BattleCompletedEvent</seealso>
[Serializable]
public sealed class BattleRules
{
private readonly int battlefieldWidth;
private readonly int battlefieldHeight;
private readonly int numRounds;
private readonly double gunCoolingRate;
private readonly long inactivityTime;
private readonly bool hideEnemyNames;
private readonly int sentryBorderSize;
///<summary>
/// Returns the battlefield width.
///</summary>
public int BattlefieldWidth
{
get { return battlefieldWidth; }
}
///<summary>
/// Returns the battlefield height.
///</summary>
public int BattlefieldHeight
{
get { return battlefieldHeight; }
}
///<summary>
/// Returns the number of rounds.
///</summary>
public int NumRounds
{
get { return numRounds; }
}
///<summary>
/// Returns the rate at which the gun will cool down, i.e. the amount of heat the gun heat will drop per turn.
/// <p />
/// The gun cooling rate is default 0.1 per turn, but can be changed by the battle setup.
/// So don't count on the cooling rate being 0.1!
/// <seealso cref="Robot.GunHeat"/>
/// <seealso cref="Robot.Fire(double)"/>
/// <seealso cref="Robot.FireBullet(double)"/>
///</summary>
public double GunCoolingRate
{
get { return gunCoolingRate; }
}
///<summary>
/// Returns the allowed inactivity time, where the robot is not taking any action, before will begin to be zapped.
/// The inactivity time is measured in turns, and is the allowed time that a robot is allowed to omit taking
/// action before being punished by the game by zapping.
/// <p />
/// When a robot is zapped by the game, it will loose 0.1 energy points per turn. Eventually the robot will be
/// killed by zapping until the robot takes action. When the robot takes action, the inactivity time counter is
/// reset.
/// <p />
/// The allowed inactivity time is per default 450 turns, but can be changed by the battle setup.
/// So don't count on the inactivity time being 450 turns!
/// <seealso cref="Robot.DoNothing()"/>
/// <seealso cref="AdvancedRobot.Execute()"/>
///</summary>
public long InactivityTime
{
get { return inactivityTime; }
}
///<summary>
/// Returns true if the enemy names are hidden, i.e. anonymous; false otherwise.
///</summary>
public bool HideEnemyNames
{
get { return hideEnemyNames; }
}
///<summary>
/// Returns the sentry border size for a <see cref="Robocode.BorderSentry">BorderSentry</see> that defines the how
/// far a BorderSentry is allowed to move from the border edges measured in units.<br/>
/// Hence, the sentry border size defines the width/range of the border area surrounding the battlefield that
/// BorderSentrys cannot leave (sentry robots robots must stay in the border area), but it also define the
/// distance from the border edges where BorderSentrys are allowed/able to make damage to robots entering this
/// border area.
///</summary>
public int SentryBorderSize
{
get { return sentryBorderSize; }
}
private BattleRules(int battlefieldWidth, int battlefieldHeight, int numRounds, double gunCoolingRate, long inactivityTime,
bool hideEnemyNames, int sentryBorderSize)
{
this.battlefieldWidth = battlefieldWidth;
this.battlefieldHeight = battlefieldHeight;
this.numRounds = numRounds;
this.gunCoolingRate = gunCoolingRate;
this.inactivityTime = inactivityTime;
this.hideEnemyNames = hideEnemyNames;
this.sentryBorderSize = sentryBorderSize;
}
private static IHiddenRulesHelper createHiddenHelper()
{
return new HiddenHelper();
}
private class HiddenHelper : IHiddenRulesHelper
{
public BattleRules createRules(int battlefieldWidth, int battlefieldHeight, int numRounds, double gunCoolingRate, long inactivityTime,
bool hideEnemyNames, int borderSentryRobotAttackRange)
{
return new BattleRules(battlefieldWidth, battlefieldHeight, numRounds, gunCoolingRate, inactivityTime, hideEnemyNames, borderSentryRobotAttackRange);
}
}
}
}
//doc

View File

@ -0,0 +1,217 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.security;
using net.sf.robocode.serialization;
using Robocode.Util;
namespace Robocode
{
///
///<summary>
/// Represents a bullet. This is returned from <see cref="Robot.FireBullet(double)"/>
/// and <see cref="AdvancedRobot.SetFireBullet(double)"/>, and all the bullet-related
/// events.
/// <seealso cref="Robot.FireBullet(double)"/>
/// <seealso cref="AdvancedRobot.SetFireBullet(double)"/>
/// <seealso cref="BulletHitEvent"/>
/// <seealso cref="BulletMissedEvent"/>
/// <seealso cref="BulletHitBulletEvent"/>
///</summary>
[Serializable]
public class Bullet
{
private readonly double headingRadians;
private double x;
private double y;
private readonly double power;
private readonly string ownerName;
private string victimName;
private bool _isActive;
private readonly int bulletId;
///<summary>
/// Called by the game to create a new Bullet object
///</summary>
public Bullet(double heading, double x, double y, double power, string ownerName, string victimName,
bool isActive, int bulletId)
{
headingRadians = heading;
this.x = x;
this.y = y;
this.power = power;
this.ownerName = ownerName;
this.victimName = victimName;
_isActive = isActive;
this.bulletId = bulletId;
}
public override bool Equals(Object obj)
{
if (obj is Bullet)
{
Bullet bullet = (Bullet)obj;
return bullet.bulletId == bulletId;
}
return Equals(obj);
}
///<summary>
/// Returns the direction the bullet is/was heading, in degrees
/// (0 &lt;= getHeading() &lt; 360). This is not relative to the direction you are facing.
///</summary>
public double Heading
{
get { return Utils.ToDegrees(headingRadians); }
}
///<summary>
/// Returns the direction the bullet is/was heading, in radians
/// (0 &lt;= getHeadingRadians() &lt; 2 * Math.PI). This is not relative to the direction you are facing.
///</summary>
public double HeadingRadians
{
get { return headingRadians; }
}
///<summary>
/// Returns the name of the robot that fired this bullet.
///</summary>
public string Name
{
get { return ownerName; }
}
///<summary>
/// Returns the power of this bullet.
/// <p />
/// The bullet will do (4 * power) damage if it hits another robot.
/// If power is greater than 1, it will do an additional 2 * (power - 1)
/// damage. You will get (3 * power) back if you hit the other robot.
///</summary>
public double Power
{
get { return power; }
}
///<summary>
/// Returns the velocity of this bullet. The velocity of the bullet is
/// constant once it has been fired.
///</summary>
public double Velocity
{
get { return Rules.GetBulletSpeed(power); }
}
///<summary>
/// Returns the name of the robot that this bullet hit, or null if
/// the bullet has not hit a robot.
///</summary>
public string Victim
{
get { return victimName; }
}
///<summary>
/// Returns the X position of the bullet.
///</summary>
public double X
{
get { return x; }
}
///<summary>
/// Returns the Y position of the bullet.
///</summary>
public double Y
{
get { return y; }
}
///<summary>
/// Checks if this bullet is still active on the battlefield.
///</summary>
public bool IsActive
{
get { return _isActive; }
}
///<summary>
/// Updates this bullet based on the specified bullet status.
///</summary>
// this method is invisible on RobotAPI
private void update(double x, double y, string victimName, bool isActive)
{
this.x = x;
this.y = y;
this.victimName = victimName;
_isActive = isActive;
}
internal int getBulletId()
{
return bulletId;
}
private static IHiddenBulletHelper createHiddenHelper()
{
return new HiddenBulletHelper();
}
private static ISerializableHelperN createHiddenSerializer()
{
return new HiddenBulletHelper();
}
private class HiddenBulletHelper : IHiddenBulletHelper, ISerializableHelperN
{
public void update(Bullet bullet, double x, double y, string victimName, bool isActive)
{
bullet.update(x, y, victimName, isActive);
}
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (Bullet)objec;
return RbSerializerN.SIZEOF_TYPEINFO + 4 * RbSerializerN.SIZEOF_DOUBLE + serializer.sizeOf(obj.ownerName)
+ serializer.sizeOf(obj.victimName) + RbSerializerN.SIZEOF_BOOL + RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (Bullet)objec;
serializer.serialize(buffer, obj.headingRadians);
serializer.serialize(buffer, obj.x);
serializer.serialize(buffer, obj.y);
serializer.serialize(buffer, obj.power);
serializer.serialize(buffer, obj.ownerName);
serializer.serialize(buffer, obj.victimName);
serializer.serialize(buffer, obj._isActive);
serializer.serialize(buffer, obj.bulletId);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
double headingRadians = buffer.getDouble();
double x = buffer.getDouble();
double y = buffer.getDouble();
double power = buffer.getDouble();
string ownerName = serializer.deserializeString(buffer);
string victimName = serializer.deserializeString(buffer);
bool isActive = serializer.deserializeBoolean(buffer);
int bulletId = serializer.deserializeInt(buffer);
return new Bullet(headingRadians, x, y, power, ownerName, victimName, isActive, bulletId);
}
}
}
}
//doc

View File

@ -0,0 +1,116 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
///<summary>
/// This event is sent to <see cref="Robot.OnBulletHitBullet(BulletHitBulletEvent)"/>
/// when one of your bullets has hit another bullet.
///</summary>
[Serializable]
public sealed class BulletHitBulletEvent : Event
{
private const int DEFAULT_PRIORITY = 55;
private Bullet bullet;
private readonly Bullet hitBullet;
///<summary>
/// Called by the game to create a new BulletHitEvent.
///</summary>
public BulletHitBulletEvent(Bullet bullet, Bullet hitBullet)
{
this.bullet = bullet;
this.hitBullet = hitBullet;
}
///<summary>
/// Returns your bullet that hit another bullet.
///</summary>
public Bullet Bullet
{
get { return bullet; }
}
///<summary>
/// Returns the bullet that was hit by your bullet.
///</summary>
public Bullet HitBullet
{
get { return hitBullet; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnBulletHitBullet(this);
}
}
// Needed for .NET version
internal override void UpdateBullets(Dictionary<int, Bullet> bullets)
{
// we need to pass same instance
bullet = bullets[bullet.getBulletId()];
}
internal override byte SerializationType
{
get { return RbSerializerN.BulletHitBulletEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (BulletHitBulletEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_INT
+ serializer.sizeOf(RbSerializerN.Bullet_TYPE, obj.hitBullet);
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (BulletHitBulletEvent) objec;
// no need to transmit whole bullet, rest of it is already known to proxy side
serializer.serialize(buffer, obj.bullet.getBulletId());
serializer.serialize(buffer, RbSerializerN.Bullet_TYPE, obj.hitBullet);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
var bullet = new Bullet(0, 0, 0, 0, null, null, false, buffer.getInt());
var hitBullet = (Bullet) serializer.deserializeAny(buffer);
return new BulletHitBulletEvent(bullet, hitBullet);
}
}
}
}
//doc

View File

@ -0,0 +1,128 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
///<summary>
/// This event is sent to <see cref="Robot.OnBulletHit(BulletHitEvent)"/>
/// when one of your bullets has hit another robot.
///</summary>
[Serializable]
public sealed class BulletHitEvent : Event
{
private const int DEFAULT_PRIORITY = 50;
private readonly string name;
private readonly double energy;
private Bullet bullet;
///<summary>
/// Called by the game to create a new BulletHitEvent.
///</summary>
public BulletHitEvent(string name, double energy, Bullet bullet)
{
this.name = name;
this.energy = energy;
this.bullet = bullet;
}
///<summary>
/// Returns the bullet of yours that hit the robot.
///</summary>
public Bullet Bullet
{
get { return bullet; }
}
///<summary>
/// Returns the remaining energy of the robot your bullet has hit (after the
/// damage done by your bullet).
///</summary>
public double VictimEnergy
{
get { return energy; }
}
///<summary>
/// Returns the name of the robot your bullet hit.
///</summary>
public string VictimName
{
get { return name; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnBulletHit(this);
}
}
// Needed for .NET version
internal override void UpdateBullets(Dictionary<int, Bullet> bullets)
{
// we need to pass same instance
bullet = bullets[bullet.getBulletId()];
}
internal override byte SerializationType
{
get { return RbSerializerN.BulletHitEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (BulletHitEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_INT + serializer.sizeOf(obj.name)
+ RbSerializerN.SIZEOF_DOUBLE;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (BulletHitEvent) objec;
serializer.serialize(buffer, obj.bullet.getBulletId());
serializer.serialize(buffer, obj.name);
serializer.serialize(buffer, obj.energy);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
var bullet = new Bullet(0, 0, 0, 0, null, null, false, buffer.getInt());
string name = serializer.deserializeString(buffer);
double energy = buffer.getDouble();
return new BulletHitEvent(name, energy, bullet);
}
}
}
}
//doc

View File

@ -0,0 +1,102 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
///<summary>
/// This event is sent to <see cref="Robot.OnBulletMissed(BulletMissedEvent)"/>
/// when one of your bullets has missed, i.e. when the bullet has
/// reached the border of the battlefield.
///</summary>
[Serializable]
public sealed class BulletMissedEvent : Event
{
private const int DEFAULT_PRIORITY = 60;
private Bullet bullet;
///
///<summary>
/// Called by the game to create a new BulletMissedEvent.
///</summary>
public BulletMissedEvent(Bullet bullet)
{
this.bullet = bullet;
}
///
///<summary>
/// Returns the bullet that missed.
///</summary>
public Bullet Bullet
{
get { return bullet; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnBulletMissed(this);
}
}
// Needed for .NET version
internal override void UpdateBullets(Dictionary<int, Bullet> bullets)
{
// we need to pass same instance
bullet = bullets[bullet.getBulletId()];
}
internal override byte SerializationType
{
get { return RbSerializerN.BulletMissedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (BulletMissedEvent) objec;
serializer.serialize(buffer, obj.bullet.getBulletId());
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
var bullet = new Bullet(0, 0, 0, 0, null, null, false, buffer.getInt());
return new BulletMissedEvent(bullet);
}
}
}
}
//doc

View File

@ -0,0 +1,155 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.io;
namespace Robocode
{
/// <summary>
/// Condition is used to define custom <see cref="AdvancedRobot.WaitFor(Condition)"/>
/// and custom events for an AdvancedRobot. The code below is taken from the sample robot
/// named samplecs.Target. See the samplecs/Target.cs for details.
/// <example>
/// <code>
/// AddCustomEvent(
/// new Condition("triggerhit", (c) =>
/// {
/// return Energy &lt;= trigger;
/// }));
/// </code>
/// </example>
/// <see cref="AdvancedRobot.WaitFor(Condition)"/>
/// <see cref="AdvancedRobot.AddCustomEvent(Condition)"/>
/// <see cref="AdvancedRobot.RemoveCustomEvent(Condition)"/>
/// <see cref="AdvancedRobot.OnCustomEvent(CustomEvent)"/>
/// </summary>
public class Condition
{
private readonly ConditionTest test;
/// <summary>
/// The priority of this condition. Defaults to 80.
/// </summary>
public int priority = 80;
/// <summary>
/// The name of this condition.
/// </summary>
public string name;
/// <summary>
/// Convinience constructor, allows to pass delegate to method, instead of overriding Test() method.
/// </summary>
public Condition(string name, int priority, ConditionTest test)
: this(name, priority)
{
this.test = test;
}
/// <summary>
/// Convinience constructor, allows to pass delegate to method, instead of overriding Test() method.
/// </summary>
public Condition(string name, ConditionTest test)
: this(name)
{
this.test = test;
}
/// <summary>
/// Convinience constructor, allows to pass delegate to method, instead of overriding Test() method.
/// </summary>
public Condition(ConditionTest test)
{
this.test = test;
}
/// <summary>
/// Creates a new, unnamed Condition with the default priority, which is 80.
/// </summary>
protected Condition()
{
}
/// <summary>
/// Creates a new Condition with the specified name, and default priority, which is 80.
/// </summary>
/// <param name="name">The name for the new Condition</param>
protected Condition(string name)
{
this.name = name;
}
/// <summary>
/// Creates a new Condition with the specified name and priority.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// </summary>
/// <param name="name">The name for the new condition</param>
/// <param name="priority">The priority of the new condition</param>
protected Condition(string name, int priority)
{
this.name = name;
if (priority < 0)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority must be between 0 and 99.");
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority for condition " + name + " will be 0.");
priority = 0;
}
else if (priority > 99)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority must be between 0 and 99.");
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority for condition " + name + " will be 99.");
priority = 99;
}
this.priority = priority;
}
/// <summary>
/// Returns the name of this condition.
/// </summary>
public string Name
{
get { return name ?? GetType().Name; }
set { name = value; }
}
/// <summary>
/// Returns the priority of this condition.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// </summary>
public int Priority
{
get { return priority; }
set { priority=value; }
}
/// <summary>
/// Overriding the Test() method is the point of a Condition.
/// The game will call your Test() function, and take action if it returns true.
/// This is valid for both <see cref="AdvancedRobot.WaitFor"/> and
/// <see cref="AdvancedRobot.AddCustomEvent(Condition)"/>
/// <p/>
/// You may not take any actions inside of Test().
/// </summary>
public virtual bool Test()
{
if (test != null)
{
return test(this);
}
throw new NotImplementedException("You should inherit from Condition class and override Test() method or pass delegate into constructor");
}
}
/// <summary>
/// Method signature for Test method of <see cref="Condition"/>
/// </summary>
public delegate bool ConditionTest(Condition condition);
}
//doc

View File

@ -0,0 +1,123 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.peer;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// This event is sent to <see cref="AdvancedRobot.OnCustomEvent(CustomEvent)"/>
/// when a custom condition is met. Be sure to reset or remove the custom condition to avoid
/// having it recurring repeatedly (see the example for the <see cref="Condition"/> method.
/// <seealso cref="Condition"/>
/// </summary>
[Serializable]
public class CustomEvent : Event
{
private const int DEFAULT_PRIORITY = 80;
private readonly Condition condition;
/// <summary>
/// Called by the game to create a new CustomEvent when a condition is met.
/// </summary>
public CustomEvent(Condition condition)
{
this.condition = condition;
if (condition != null)
{
Priority = condition.Priority;
}
}
/// <summary>
/// Called by the game to create a new CustomEvent when a condition is met.
/// The event will have the given priority.
/// An event priority is a value from 0 - 99. The higher value, the higher
/// priority. The default priority is 80.
/// <p/>
/// This is equivalent to calling <see cref="Robocode.Condition.Priority"/> on the
/// Condition.
/// </summary>
/// <param name="condition">The condition that must be met</param>
/// <param name="priority">The priority of the condition</param>
public CustomEvent(Condition condition, int priority)
{
this.condition = condition;
Priority = priority;
if (condition != null)
{
condition.Priority = priority;
}
}
/// <summary>
/// Returns the condition that fired, causing this event to be generated.
/// Use this to determine which condition fired, and to remove the custom event.
/// <example>
/// <code>
/// public void OnCustomEvent(CustomEvent evnt)
/// {
/// if (event.Condition.Name == "mycondition")
/// {
/// RemoveCustomEvent(event.Condition);
/// // do something else
/// }
/// }
/// </code>
/// </example>
/// </summary>
public Condition Condition
{
get { return condition; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override sealed void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsAdvancedRobot())
{
IAdvancedEvents listener = ((IAdvancedRobot) robot).GetAdvancedEventListener();
if (listener != null)
{
listener.OnCustomEvent(this);
}
}
}
// sealed to disable overrides
public override sealed int CompareTo(Event evnt)
{
return base.CompareTo(evnt);
}
// sealed to disable overrides
internal override bool IsCriticalEvent
{
get { return false; }
}
// sealed to disable overrides
public sealed override int Priority
{
get { return base.Priority; }
}
internal override byte SerializationType
{
get { throw new System.Exception("Serialization not supported on this event type"); }
}
}
}
//doc

View File

@ -0,0 +1,78 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// This event is sent to <see cref="Robot.OnDeath(DeathEvent)"/> when your robot dies.
/// </summary>
[Serializable]
public sealed class DeathEvent : Event
{
private const int DEFAULT_PRIORITY = -1; // System event -> cannot be changed!;
/// <inheritdoc />
public override int Priority
{
get { return DEFAULT_PRIORITY; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnDeath(this);
}
}
internal override bool IsCriticalEvent
{
get { return true; }
}
internal override byte SerializationType
{
get { return RbSerializerN.DeathEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
return new DeathEvent();
}
}
}
}
//doc

View File

@ -0,0 +1,279 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Collections.Generic;
using net.sf.robocode.io;
using net.sf.robocode.peer;
using net.sf.robocode.security;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// The superclass of all Robocode events.
/// </summary>
[Serializable]
public abstract class Event : IComparable<Event>
{
private const int DEFAULT_PRIORITY = 80;
private long time;
private int priority;
// time is valid only after adding to event manager on proxy side, we do not update it on battle side
private volatile bool addedToQueue;
/// <summary>
/// Compares this event to another event regarding precedence.
/// <para>
/// The event precedence is first and foremost determined by the event time,
/// secondly the event priority, and lastly specific event information.</para>
/// <para>
/// This method will first compare the time of each event. If the event time
/// is the same for both events, then this method compared the priority of
/// each event. If the event priorities are equals, then this method will
/// compare the two events based on specific event information.</para>
/// <para>
/// This method is called by the game in order to sort the event queue of a
/// robot to make sure the events are listed in chronological order.</para>
/// </summary>
///
/// <param name="evnt">the event to compare to this event.</param>
/// <returns>
/// Returns a negative value if this event has higher precedence, i.e. must
/// be listed before the specified event. A positive value if this event
/// has a lower precedence, i.e. must be listed after the specified event.
/// 0 means that the precedence of the two events are equal.
/// </returns>
public virtual int CompareTo(Event evnt)
{
// Compare the time difference which has precedence over priority.
var timeDiff = (int) (time - evnt.time);
if (timeDiff != 0)
{
return timeDiff; // Time differ
}
// Same time -> Compare the difference in priority
int priorityDiff = evnt.Priority - Priority;
if (priorityDiff != 0)
{
return priorityDiff; // Priority differ
}
// Same time and priority -> Compare specific event types
// look at overrides in ScannedRobotEvent and HitRobotEvent
// No difference found
return 0;
}
/// <summary>
/// The time when this event occurred.
/// </summary>
/// <remarks>
/// Note that the time is equal to the turn of a battle round.
/// <para>
/// This method is intended for letting robot developers create their own event types.
/// It is not possible to change the time of an event after it has been added to the event
/// queue of the robot.</para>
/// </remarks>
public long Time
{
get { return time; }
set
{
if (addedToQueue)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: The time of an event cannot be changed after it has been added the event queue.");
}
else
{
time = value;
}
}
}
/// <summary>
/// The priority of this event.
/// <para>
/// An event priority is a value from 0 - 99. The higher value, the higher priority.</para>
/// <para>
/// The default priority is 80, but varies depending on the type of event.</para>
/// </summary>
/// <remarks>
/// This method is intended for letting robot developers create their own event types.
/// <para>
/// It is not possible to change the priority of an event after it has been added to the event
/// queue of the robot.</para>
/// </remarks>
/// <seealso cref="SetEventPriority(string, int)"/>
public virtual int Priority
{
get { return priority; }
set
{
if (addedToQueue)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: The priority of an event cannot be changed after it has been added the event queue.");
}
else
{
SetPriorityHidden(value);
}
}
}
/// <summary>
/// Hidden method for setting the exact time when this event occurred.
/// </summary>
/// <remarks>
/// This method is called by the game engine only.
/// </remarks>
/// <param name="time">the time when this event occurred.</param>
// This method must be invisible on Robot API
private void SetTimeHidden(long time)
{
// we do not replace time which is set by robot to the future
if (this.time < time)
{
this.time = time;
}
// when this flag is set, robots are not allowed to change the time or priority of the event anymore
addedToQueue = true;
}
/// <summary>
/// Hidden method for setting the priority from the game engine without checking for the 'addedToQueue' flag.
/// </summary>
/// <remarks>
/// This method is called by the game engine only.
/// </remarks>
/// <param name="newPriority">the new priority of this event.</param>
// This method must be invisible on Robot API
private void SetPriorityHidden(int newPriority)
{
if (newPriority < 0)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority must be between 0 and 99");
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority for " + GetType().Name + " will be 0");
newPriority = 0;
}
else if (newPriority > 99)
{
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority must be between 0 and 99");
LoggerN.WriteLineToRobotsConsole("SYSTEM: Priority for " + GetType().Name + " will be 99");
newPriority = 99;
}
priority = newPriority;
}
/// <summary>
/// Dispatch this event for a robot, it's statistics, and graphics context.
/// </summary>
/// <param name="robot">the robot to dispatch to.</param>
/// <param name="statics">the robot to statistics to.</param>
/// <param name="graphics">the robot to graphics to.</param>
// This method must be invisible on Robot API
internal virtual void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
}
/// <summary>
/// The default priority of this event class.
/// </summary>
// This method must be invisible on Robot API
internal virtual int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
/// <summary>
/// Checks if this event must be delivered even after timeout.
/// </summary>
/// <returns>
/// <c>true</c> when this event must be delivered even after timeout;
/// <c>false</c> otherwise.
/// </returns>
// This method must be invisible on Robot API
internal virtual bool IsCriticalEvent
{
get { return false; }
}
// This method must be invisible on Robot API
internal virtual byte SerializationType
{
get { throw new System.Exception("Serialization not supported on this event type"); }
}
// Needed for .NET version
// This method must be invisible on Robot API
internal virtual void UpdateBullets(Dictionary<int, Bullet> bullets)
{
}
/// <summary>
/// Returns a hidden event helper for accessing hidden methods on this object.
/// </summary>
// This method must be invisible on Robot API
private static IHiddenEventHelper createHiddenHelper()
{
return new HiddenEventHelper();
}
/// <summary>
/// Hidden event helper implementation for accessing the internal methods of an event.
/// </summary>
/// <remarks>
/// This class is used internally by the game engine.
/// </remarks>
// This method must be invisible on Robot API
private class HiddenEventHelper : IHiddenEventHelper
{
public void SetTime(Event evnt, long newTime)
{
evnt.SetTimeHidden(newTime);
}
public void SetDefaultPriority(Event evnt)
{
evnt.Priority = evnt.DefaultPriority;
}
public void SetPriority(Event evnt, int newPriority)
{
evnt.SetPriorityHidden(newPriority);
}
public bool IsCriticalEvent(Event evnt)
{
return evnt.IsCriticalEvent;
}
public void Dispatch(Event evnt, IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
evnt.Dispatch(robot, statics, graphics);
}
public byte GetSerializationType(Event evnt)
{
return evnt.SerializationType;
}
// Needed for .NET version
public void UpdateBullets(Event evnt, Dictionary<int, Bullet> bullets)
{
evnt.UpdateBullets(bullets);
}
}
}
}
//doc

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// A prebuilt condition you can use that indicates your gun has finished turning.
/// <seealso cref="Condition"/>
/// </summary>
public class GunTurnCompleteCondition : Condition
{
private readonly AdvancedRobot robot;
/// <summary>
/// Creates a new GunTurnCompleteCondition with default priority.
/// The default priority is 80.
/// </summary>
/// <param name="robot">Your robot, which must be an <see cref="AdvancedRobot"/></param>
public GunTurnCompleteCondition(AdvancedRobot robot)
{
this.robot = robot;
}
/// <summary>
/// Creates a new GunTurnCompleteCondition with a specific priority.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// <seealso cref="Condition.Priority"/>
/// </summary>
/// <param name="robot">Your robot, which must be an <see cref="AdvancedRobot"/></param>
/// <param name="priority">The priority of this condition</param>
public GunTurnCompleteCondition(AdvancedRobot robot, int priority)
{
this.robot = robot;
this.priority = priority;
}
/// <summary>
/// Tests if the gun has stopped turning.
/// Returns true if the gun has stopped turning
/// </summary>
public override bool Test()
{
return (robot.GunTurnRemaining == 0);
}
}
}
//doc

View File

@ -0,0 +1,177 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A HitByBulletEvent is sent to <see cref="Robot.OnHitByBullet(HitByBulletEvent)"/>
/// when your robot has been hit by a bullet.
/// You can use the information contained in this event to determine what to do.
/// </summary>
[Serializable]
public sealed class HitByBulletEvent : Event
{
private const int DEFAULT_PRIORITY = 20;
private readonly double bearing;
private readonly Bullet bullet;
/// <summary>
/// Called by the game to create a new HitByBulletEvent.
/// </summary>
public HitByBulletEvent(double bearing, Bullet bullet)
{
this.bearing = bearing;
this.bullet = bullet;
}
/// <summary>
/// Returns the bearing to the bullet, relative to your robot's heading,
/// in degrees (-180 &lt; getBearing() &lt;= 180).
/// <p/>
/// If you were to TurnRight(event.Bearing), you would be facing the
/// direction the bullet came from. The calculation used here is:
/// (bullet's heading in degrees + 180) - (your heading in degrees)
/// </summary>
public double Bearing
{
get { return bearing*180.0/Math.PI; }
}
/// <summary>
/// Returns the bearing to the bullet, relative to your robot's heading,
/// in radians (-Math.PI &lt; getBearingRadians() &lt;= Math.PI).
/// <p/>
/// If you were to TurnRightRadians(event.BearingRadians), you would be
/// facing the direction the bullet came from. The calculation used here is:
/// (bullet's heading in radians + Math.PI) - (your heading in radians)
/// </summary>
public double BearingRadians
{
get { return bearing; }
}
/// <summary>
/// Returns the bullet that hit your robot.
/// </summary>
public Bullet Bullet
{
get { return bullet; }
}
/// <summary>
/// Returns the heading of the bullet when it hit you, in degrees
/// (0 &lt;= getHeading() &lt; 360).
/// <p/>
/// Note: This is not relative to the direction you are facing. The robot
/// that fired the bullet was in the opposite direction of getHeading() when
/// it fired the bullet.
/// </summary>
public double Heading
{
get { return bullet.Heading; }
}
/// <summary>
/// Returns the heading of the bullet when it hit you, in radians
/// (0 &lt;= getHeadingRadians() &lt; 2 * PI).
/// <p/>
/// Note: This is not relative to the direction you are facing. The robot
/// that fired the bullet was in the opposite direction of
/// getHeadingRadians() when it fired the bullet.
/// </summary>
public double HeadingRadians
{
get { return bullet.HeadingRadians; }
}
/// <summary>
/// Returns the name of the robot that fired the bullet.
/// </summary>
public string Name
{
get { return bullet.Name; }
}
/// <summary>
/// Returns the power of this bullet. The damage you take (in fact, already
/// took) is 4 * power, plus 2 * (power-1) if power > 1. The robot that fired
/// the bullet receives 3 * power back.
/// </summary>
public double Power
{
get { return bullet.Power; }
}
/// <summary>
/// Returns the velocity of this bullet.
/// </summary>
public double Velocity
{
get { return bullet.Velocity; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnHitByBullet(this);
}
}
internal override byte SerializationType
{
get { return RbSerializerN.HitByBulletEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (HitByBulletEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + serializer.sizeOf(RbSerializerN.Bullet_TYPE, obj.bullet)
+ RbSerializerN.SIZEOF_DOUBLE;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (HitByBulletEvent) objec;
serializer.serialize(buffer, RbSerializerN.Bullet_TYPE, obj.bullet);
serializer.serialize(buffer, obj.bearing);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
var bullet = (Bullet) serializer.deserializeAny(buffer);
double bearing = buffer.getDouble();
return new HitByBulletEvent(bearing, bullet);
}
}
}
}
//doc

View File

@ -0,0 +1,172 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A HitRobotEvent is sent to <see cref="Robot.OnHitRobot(HitRobotEvent)"/>
/// when your robot collides with another robot.
/// You can use the information contained in this event to determine what to do.
/// </summary>
[Serializable]
public sealed class HitRobotEvent : Event
{
private const int DEFAULT_PRIORITY = 40;
private readonly string name;
private readonly double bearing;
private readonly double energy;
private readonly bool atFault;
/// <summary>
/// Called by the game to create a new HitRobotEvent.
/// </summary>
public HitRobotEvent(string name, double bearing, double energy, bool atFault)
{
this.name = name;
this.bearing = bearing;
this.energy = energy;
this.atFault = atFault;
}
/// <summary>
/// Returns the bearing to the robot you hit, relative to your robot's
/// heading, in degrees (-180 &lt;= getBearing() &lt; 180)
/// </summary>
public double Bearing
{
get { return bearing*180.0/Math.PI; }
}
/// <summary>
/// Returns the bearing to the robot you hit, relative to your robot's
/// heading, in radians (-PI &lt;= getBearingRadians() &lt; PI)
/// </summary>
public double BearingRadians
{
get { return bearing; }
}
/// <summary>
/// Returns the amount of energy of the robot you hit.
/// </summary>
public double Energy
{
get { return energy; }
}
/// <summary>
/// Returns the name of the robot you hit.
/// </summary>
public string Name
{
get { return name; }
}
/// <summary>
/// Checks if your robot was moving towards the robot that was hit.
/// <p/>
/// If <see cref="IsMyFault"/> returns true then your robot's movement (including
/// turning) will have stopped and been marked complete.
/// <p/>
/// Note: If two robots are moving toward each other and collide, they will
/// each receive two HitRobotEvents. The first will be the one if isMyFault()
/// returns true.
/// </summary>
public bool IsMyFault
{
get { return atFault; }
}
/// <inheritdoc />
public override int CompareTo(Event evnt)
{
int res = base.CompareTo(evnt);
if (res != 0)
{
return res;
}
// Compare the IsMyFault, if the events are HitRobotEvents
// The isMyFault has higher priority when it is set compared to when it is not set
if (evnt is HitRobotEvent)
{
int compare1 = (this).IsMyFault ? -1 : 0;
int compare2 = ((HitRobotEvent) evnt).IsMyFault ? -1 : 0;
return compare1 - compare2;
}
// No difference found
return 0;
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnHitRobot(this);
}
}
internal override byte SerializationType
{
get { return RbSerializerN.HitRobotEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (HitRobotEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + serializer.sizeOf(obj.name) + 2*RbSerializerN.SIZEOF_DOUBLE
+ RbSerializerN.SIZEOF_BOOL;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (HitRobotEvent) objec;
serializer.serialize(buffer, obj.name);
serializer.serialize(buffer, obj.bearing);
serializer.serialize(buffer, obj.energy);
serializer.serialize(buffer, obj.atFault);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
string robotName = serializer.deserializeString(buffer);
double bearing = buffer.getDouble();
double energy = buffer.getDouble();
bool atFault = serializer.deserializeBoolean(buffer);
return new HitRobotEvent(robotName, bearing, energy, atFault);
}
}
}
}
//doc

View File

@ -0,0 +1,103 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A HitWallEvent is sent to <see cref="Robot.OnHitWall(HitWallEvent)"/>
/// when you collide a wall.
/// You can use the information contained in this event to determine what to do.
/// </summary>
[Serializable]
public sealed class HitWallEvent : Event
{
private const int DEFAULT_PRIORITY = 30;
private readonly double bearing;
/// <summary>
/// Called by the game to create a new HitWallEvent.
/// </summary>
public HitWallEvent(double bearing)
{
this.bearing = bearing;
}
/// <summary>
/// Returns the bearing to the wall you hit, relative to your robot's
/// heading, in degrees (-180 &lt;= getBearing() &lt; 180)
/// </summary>
public double Bearing
{
get { return bearing*180.0/Math.PI; }
}
/// <summary>
/// Returns the bearing to the wall you hit, relative to your robot's
/// heading, in radians (-PI &lt;= getBearingRadians() &lt; PI)
/// </summary>
public double BearingRadians
{
get { return bearing; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnHitWall(this);
}
}
internal override byte SerializationType
{
get { return RbSerializerN.HitWallEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_DOUBLE;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (HitWallEvent) objec;
serializer.serialize(buffer, obj.bearing);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
double bearing = buffer.getDouble();
return new HitWallEvent(bearing);
}
}
}
}
//doc

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// A robot that implement IBorderSentry is a robot type used for keeping other robots away from the borders,
/// i.e. guarding the borders in order to prevent "wall crawlers".<br/>
/// Robots that implement IBorderSentry have 400 extra life/energy (500 in total), but is placed at the border
/// of the battlefield when the game is started.<br/>
/// Border sentry robots cannot move away from the border area, and they can only make damage to robots that
/// are moving into the border area. The size of the border area is determined by the
/// <see cref="BattleRules.SentryBorderSize">battle rules</see>.<br/>
/// This type of robot is intended for use in battles where robots should be forced away from the borders in
/// order to prevent "wall crawlers".<br/>
/// Border sentry robots does not get scores, and will not occur in the battle results or rankings.
/// </summary>
/// <seealso cref="BattleRules.SentryBorderSize"/>
/// <seealso cref="JuniorRobot"/>
/// <seealso cref="Robot"/>
/// <seealso cref="AdvancedRobot"/>
/// <seealso cref="TeamRobot"/>
/// <seealso cref="RateControlRobot"/>
/// <seealso cref="IDroid"/>
public interface IBorderSentry
{
}
}

View File

@ -0,0 +1,23 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// Robots that implement IDroid have no scanner, but an extra 20 life/energy.
/// This class is intended for use in teams.
/// <seealso cref="JuniorRobot"/>
/// <seealso cref="Robot"/>
/// <seealso cref="AdvancedRobot"/>
/// <seealso cref="TeamRobot"/>
/// <seealso cref="RateControlRobot"/>
/// <seealso cref="IBorderSentry"/>
/// </summary>
public interface IDroid
{
}
}

View File

@ -0,0 +1,160 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System.Drawing;
namespace Robocode
{
/// <summary>
/// <see cref="Graphics"/>
/// </summary>
public interface IGraphics
{
#pragma warning disable 1591
//TODO xml doc
void DrawLine(Pen pen, float x1, float y1, float x2, float y2);
void DrawLine(Pen pen, PointF pt1, PointF pt2);
void DrawLine(Pen pen, int x1, int y1, int x2, int y2);
void DrawLine(Pen pen, Point pt1, Point pt2);
void DrawArc(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
void DrawArc(Pen pen, RectangleF rect, float startAngle, float sweepAngle);
void DrawArc(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle);
void DrawArc(Pen pen, Rectangle rect, float startAngle, float sweepAngle);
void DrawRectangle(Pen pen, RectangleF rect);
void DrawRectangle(Pen pen, Rectangle rect);
void DrawRectangle(Pen pen, float x, float y, float width, float height);
void DrawRectangle(Pen pen, int x, int y, int width, int height);
void DrawEllipse(Pen pen, RectangleF rect);
void DrawEllipse(Pen pen, float x, float y, float width, float height);
void DrawEllipse(Pen pen, Rectangle rect);
void DrawEllipse(Pen pen, int x, int y, int width, int height);
void DrawPie(Pen pen, RectangleF rect, float startAngle, float sweepAngle);
void DrawPie(Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
void DrawPie(Pen pen, Rectangle rect, float startAngle, float sweepAngle);
void DrawPie(Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle);
void DrawPolygon(Pen pen, PointF[] points);
void DrawPolygon(Pen pen, Point[] points);
void FillRectangle(Brush brush, RectangleF rect);
void FillRectangle(Brush brush, float x, float y, float width, float height);
void FillRectangle(Brush brush, Rectangle rect);
void FillRectangle(Brush brush, int x, int y, int width, int height);
void FillPolygon(Brush brush, PointF[] points);
void FillPolygon(Brush brush, Point[] points);
void FillEllipse(Brush brush, RectangleF rect);
void FillEllipse(Brush brush, float x, float y, float width, float height);
void FillEllipse(Brush brush, Rectangle rect);
void FillEllipse(Brush brush, int x, int y, int width, int height);
void FillPie(Brush brush, Rectangle rect, float startAngle, float sweepAngle);
void FillPie(Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle);
void FillPie(Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle);
void DrawString(string s, Font font, Brush brush, int x, int y);
void DrawString(string s, Font font, Brush brush, float x, float y);
void DrawString(string s, Font font, Brush brush, PointF point);
void DrawString(string s, Font font, Brush brush, Point point);
/*
void DrawLines(Pen pen, PointF[] points);
void DrawLines(Pen pen, Point[] points);
void DrawRectangles(Pen pen, RectangleF[] rects);
void DrawRectangles(Pen pen, Rectangle[] rects);
void DrawPath(Pen pen, GraphicsPath path);
void DrawCurve(Pen pen, PointF[] points);
void DrawCurve(Pen pen, PointF[] points, float tension);
void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments);
void DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension);
void DrawCurve(Pen pen, Point[] points);
void DrawCurve(Pen pen, Point[] points, float tension);
void DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension);
void DrawClosedCurve(Pen pen, PointF[] points);
void DrawClosedCurve(Pen pen, PointF[] points, float tension, FillMode fillmode);
void DrawClosedCurve(Pen pen, Point[] points);
void DrawClosedCurve(Pen pen, Point[] points, float tension, FillMode fillmode);
void FillPolygon(Brush brush, PointF[] points, FillMode fillMode);
void FillPolygon(Brush brush, Point[] points, FillMode fillMode);
void FillRectangles(Brush brush, RectangleF[] rects);
void FillRectangles(Brush brush, Rectangle[] rects);
void FillClosedCurve(Brush brush, PointF[] points);
void FillClosedCurve(Brush brush, PointF[] points, FillMode fillmode);
void FillClosedCurve(Brush brush, PointF[] points, FillMode fillmode, float tension);
void FillClosedCurve(Brush brush, Point[] points);
void FillClosedCurve(Brush brush, Point[] points, FillMode fillmode);
void FillClosedCurve(Brush brush, Point[] points, FillMode fillmode, float tension);
void FillRegion(Brush brush, Region region);
void FillPath(Brush brush, GraphicsPath path);
void DrawString(string s, Font font, Brush brush, float x, float y, StringFormat format);
void DrawString(string s, Font font, Brush brush, PointF point, StringFormat format);
void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle);
void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format);
SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat,
out int charactersFitted, out int linesFilled);
SizeF MeasureString(string text, Font font, PointF origin, StringFormat stringFormat);
SizeF MeasureString(string text, Font font, SizeF layoutArea);
SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat);
SizeF MeasureString(string text, Font font);
SizeF MeasureString(string text, Font font, int width);
SizeF MeasureString(string text, Font font, int width, StringFormat format);
Region[] MeasureCharacterRanges(string text, Font font, RectangleF layoutRect, StringFormat stringFormat);
void ResetTransform();
void MultiplyTransform(Matrix matrix);
void MultiplyTransform(Matrix matrix, MatrixOrder order);
void TranslateTransform(float dx, float dy);
void TranslateTransform(float dx, float dy, MatrixOrder order);
void ScaleTransform(float sx, float sy);
void ScaleTransform(float sx, float sy, MatrixOrder order);
void RotateTransform(float angle);
void RotateTransform(float angle, MatrixOrder order);
void TransformPoints(CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF[] pts);
void TransformPoints(CoordinateSpace destSpace, CoordinateSpace srcSpace, Point[] pts);
void SetClip(Graphics g);
void SetClip(Graphics g, CombineMode combineMode);
void SetClip(Rectangle rect);
void SetClip(Rectangle rect, CombineMode combineMode);
void SetClip(RectangleF rect);
void SetClip(RectangleF rect, CombineMode combineMode);
void SetClip(GraphicsPath path);
void SetClip(GraphicsPath path, CombineMode combineMode);
void SetClip(Region region, CombineMode combineMode);
void IntersectClip(Rectangle rect);
void IntersectClip(RectangleF rect);
void IntersectClip(Region region);
void ExcludeClip(Rectangle rect);
void ExcludeClip(Region region);
void ResetClip();
void TranslateClip(float dx, float dy);
void TranslateClip(int dx, int dy);
bool IsVisible(int x, int y);
bool IsVisible(Point point);
bool IsVisible(float x, float y);
bool IsVisible(PointF point);
bool IsVisible(int x, int y, int width, int height);
bool IsVisible(Rectangle rect);
bool IsVisible(float x, float y, float width, float height);
bool IsVisible(RectangleF rect);
CompositingMode CompositingMode { get; set; }
Point RenderingOrigin { get; set; }
CompositingQuality CompositingQuality { get; set; }
TextRenderingHint TextRenderingHint { get; set; }
int TextContrast { get; set; }
SmoothingMode SmoothingMode { get; set; }
PixelOffsetMode PixelOffsetMode { get; set; }
InterpolationMode InterpolationMode { get; set; }
Matrix Transform { get; set; }
GraphicsUnit PageUnit { get; set; }
float PageScale { get; set; }
float DpiX { get; }
float DpiY { get; }
Region Clip { get; set; }
RectangleF ClipBounds { get; }
bool IsClipEmpty { get; }
RectangleF VisibleClipBounds { get; }
bool IsVisibleClipEmpty { get; }
*/
}
}

View File

@ -0,0 +1,78 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
namespace Robocode
{
/// <summary>
/// Super class of all events that originates from the keyboard.
/// </summary>
[Serializable]
public abstract class KeyEvent : Event
{
private readonly char keyChar;
private readonly int keyCode;
private readonly int keyLocation;
private readonly int id;
private readonly int modifiersEx;
private readonly long when;
/// <summary>
/// Called by game
/// </summary>
protected KeyEvent(char keyChar, int keyCode, int keyLocation, int id, int modifiersEx, long when)
{
this.keyChar = keyChar;
this.keyCode = keyCode;
this.keyLocation = keyLocation;
this.id = id;
this.modifiersEx = modifiersEx;
this.when = when;
}
/// <summary>
/// Char of they key pressed
/// </summary>
public char KeyChar
{
get { return keyChar; }
}
/// <summary>
/// <see cref="Keys"/>
/// </summary>
public int KeyCode
{
get { return keyCode; }
}
internal int KeyLocation
{
get { return keyLocation; }
}
internal int ID
{
get { return id; }
}
internal int ModifiersEx
{
get { return modifiersEx; }
}
/// <summary>
/// Age of the event
/// </summary>
public long When
{
get { return when; }
}
}
}
//doc

View File

@ -0,0 +1,96 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A KeyPressedEvent is sent to <see cref="Robot.OnKeyPressed(KeyEvent)"/>
/// when a key has been pressed on the keyboard.
/// <seealso cref="KeyReleasedEvent"/>
/// <seealso cref="KeyTypedEvent"/>
/// </summary>
[Serializable]
public sealed class KeyPressedEvent : KeyEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new KeyPressedEvent.
/// </summary>
public KeyPressedEvent(char keyChar, int keyCode, int keyLocation, int id, int modifiersEx, long when)
: base(keyChar, keyCode, keyLocation, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnKeyPressed(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.KeyPressedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_CHAR + RbSerializerN.SIZEOF_INT
+ RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG + RbSerializerN.SIZEOF_INT +
RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (KeyPressedEvent) objec;
serializer.serialize(buffer, obj.KeyChar);
serializer.serialize(buffer, obj.KeyCode);
serializer.serialize(buffer, obj.KeyLocation);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
char keyChar = buffer.getChar();
int keyCode = buffer.getInt();
int keyLocation = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new KeyPressedEvent(keyChar, keyCode, keyLocation, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,98 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A KeyReleasedEvent is sent to <see cref="Robot.OnKeyReleased(KeyEvent)"/>
/// when a key has been released on the keyboard.
/// <seealso cref="KeyPressedEvent"/>
/// <seealso cref="KeyTypedEvent"/>
/// </summary>
[Serializable]
public sealed class KeyReleasedEvent : KeyEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new KeyReleasedEvent.
/// </summary>
public KeyReleasedEvent(char keyChar, int keyCode, int keyLocation, int id, int modifiersEx, long when)
: base(keyChar, keyCode, keyLocation, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnKeyReleased(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.KeyReleasedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_CHAR + RbSerializerN.SIZEOF_INT
+ RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG + RbSerializerN.SIZEOF_INT +
RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (KeyReleasedEvent) objec;
serializer.serialize(buffer, obj.KeyChar);
serializer.serialize(buffer, obj.KeyCode);
serializer.serialize(buffer, obj.KeyLocation);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
char keyChar = buffer.getChar();
int keyCode = buffer.getInt();
int keyLocation = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new KeyReleasedEvent(keyChar, keyCode, keyLocation, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,98 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A KeyTypedEvent is sent to <see cref="Robot.OnKeyTyped(KeyEvent)"/>
/// when a key has been typed (pressed and released) on the keyboard.
/// <seealso cref="KeyPressedEvent"/>
/// <seealso cref="KeyReleasedEvent"/>
/// </summary>
[Serializable]
public sealed class KeyTypedEvent : KeyEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new KeyTypedEvent.
/// </summary>
public KeyTypedEvent(char keyChar, int keyCode, int keyLocation, int id, int modifiersEx, long when)
: base(keyChar, keyCode, keyLocation, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnKeyTyped(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.KeyTypedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_CHAR + RbSerializerN.SIZEOF_INT
+ RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG + RbSerializerN.SIZEOF_INT +
RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (KeyTypedEvent) objec;
serializer.serialize(buffer, obj.KeyChar);
serializer.serialize(buffer, obj.KeyCode);
serializer.serialize(buffer, obj.KeyLocation);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
char keyChar = buffer.getChar();
int keyCode = buffer.getInt();
int keyLocation = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new KeyTypedEvent(keyChar, keyCode, keyLocation, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,292 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
// This class is based on the source code from Sun's Java 1.5.0 API for java.awt.event.KeyEvent, but
// rewritten for C# and .NET with the purpose to bridge the .NET and Java internals of Robocode.
namespace Robocode
{
#pragma warning disable 1591
/// <exclude/>
public static class Keys
{
public const int KEY_FIRST = 400;
public const int KEY_LAST = 402;
public const int KEY_TYPED = KEY_FIRST;
public const int KEY_PRESSED = 1 + KEY_FIRST;
public const int KEY_RELEASED = 2 + KEY_FIRST;
public const int VK_ENTER = 0x0A;
public const int VK_BACK_SPACE = 0x20;
public const int VK_TAB = 0x08;
public const int VK_CANCEL = 0x03;
public const int VK_CLEAR = 0x0C;
public const int VK_SHIFT = 0x10;
public const int VK_CONTROL = 0x11;
public const int VK_ALT = 0x12;
public const int VK_PAUSE = 0x13;
public const int VK_CAPS_LOCK = 0x14;
public const int VK_ESCAPE = 0x1B;
public const int VK_SPACE = 0x20;
public const int VK_PAGE_UP = 0x21;
public const int VK_PAGE_DOWN = 0x22;
public const int VK_END = 0x23;
public const int VK_HOME = 0x24;
public const int VK_LEFT = 0x25;
public const int VK_UP = 0x26;
public const int VK_RIGHT = 0x27;
public const int VK_DOWN = 0x28;
public const int VK_COMMA = 0x2C;
public const int VK_MINUS = 0x2D;
public const int VK_PERIOD = 0x2E;
public const int VK_SLASH = 0x2F;
public const int VK_0 = 0x30;
public const int VK_1 = 0x31;
public const int VK_2 = 0x32;
public const int VK_3 = 0x33;
public const int VK_4 = 0x34;
public const int VK_5 = 0x35;
public const int VK_6 = 0x36;
public const int VK_7 = 0x37;
public const int VK_8 = 0x38;
public const int VK_9 = 0x39;
public const int VK_SEMICOLON = 0x3B;
public const int VK_EQUALS = 0x3D;
public const int VK_A = 0x41;
public const int VK_B = 0x42;
public const int VK_C = 0x43;
public const int VK_D = 0x44;
public const int VK_E = 0x45;
public const int VK_F = 0x46;
public const int VK_G = 0x47;
public const int VK_H = 0x48;
public const int VK_I = 0x49;
public const int VK_J = 0x4A;
public const int VK_K = 0x4B;
public const int VK_L = 0x4C;
public const int VK_M = 0x4D;
public const int VK_N = 0x4E;
public const int VK_O = 0x4F;
public const int VK_P = 0x50;
public const int VK_Q = 0x51;
public const int VK_R = 0x52;
public const int VK_S = 0x53;
public const int VK_T = 0x54;
public const int VK_U = 0x55;
public const int VK_V = 0x56;
public const int VK_W = 0x57;
public const int VK_X = 0x58;
public const int VK_Y = 0x59;
public const int VK_Z = 0x5A;
public const int VK_OPEN_BRACKET = 0x5B;
public const int VK_BACK_SLASH = 0x5C;
public const int VK_CLOSE_BRACKET = 0x5D;
public const int VK_NUMPAD0 = 0x60;
public const int VK_NUMPAD1 = 0x61;
public const int VK_NUMPAD2 = 0x62;
public const int VK_NUMPAD3 = 0x63;
public const int VK_NUMPAD4 = 0x64;
public const int VK_NUMPAD5 = 0x65;
public const int VK_NUMPAD6 = 0x66;
public const int VK_NUMPAD7 = 0x67;
public const int VK_NUMPAD8 = 0x68;
public const int VK_NUMPAD9 = 0x69;
public const int VK_MULTIPLY = 0x6A;
public const int VK_ADD = 0x6B;
public const int VK_SEPARATER = 0x6C;
public const int VK_SEPARATOR = VK_SEPARATER;
public const int VK_SUBTRACT = 0x6D;
public const int VK_DECIMAL = 0x6E;
public const int VK_DIVIDE = 0x6F;
public const int VK_DELETE = 0x7F;
public const int VK_NUM_LOCK = 0x90;
public const int VK_SCROLL_LOCK = 0x91;
public const int VK_F1 = 0x70;
public const int VK_F2 = 0x71;
public const int VK_F3 = 0x72;
public const int VK_F4 = 0x73;
public const int VK_F5 = 0x74;
public const int VK_F6 = 0x75;
public const int VK_F7 = 0x76;
public const int VK_F8 = 0x77;
public const int VK_F9 = 0x78;
public const int VK_F10 = 0x79;
public const int VK_F11 = 0x7A;
public const int VK_F12 = 0x7B;
public const int VK_F13 = 0xF000;
public const int VK_F14 = 0xF001;
public const int VK_F15 = 0xF002;
public const int VK_F16 = 0xF003;
public const int VK_F17 = 0xF004;
public const int VK_F18 = 0xF005;
public const int VK_F19 = 0xF006;
public const int VK_F20 = 0xF007;
public const int VK_F21 = 0xF008;
public const int VK_F22 = 0xF009;
public const int VK_F23 = 0xF00A;
public const int VK_F24 = 0xF00B;
public const int VK_PRINTSCREEN = 0x9A;
public const int VK_INSERT = 0x9B;
public const int VK_HELP = 0x9C;
public const int VK_META = 0x9D;
public const int VK_BACK_QUOTE = 0xC0;
public const int VK_QUOTE = 0xDE;
public const int VK_KP_UP = 0xE0;
public const int VK_KP_DOWN = 0xE1;
public const int VK_KP_LEFT = 0xE2;
public const int VK_KP_RIGHT = 0xE3;
public const int VK_DEAD_GRAVE = 0x80;
public const int VK_DEAD_ACUTE = 0x81;
public const int VK_DEAD_CIRCUMFLEX = 0x82;
public const int VK_DEAD_TILDE = 0x83;
public const int VK_DEAD_MACRON = 0x84;
public const int VK_DEAD_BREVE = 0x85;
public const int VK_DEAD_ABOVEDOT = 0x86;
public const int VK_DEAD_DIAERESIS = 0x87;
public const int VK_DEAD_ABOVERING = 0x88;
public const int VK_DEAD_DOUBLEACUTE = 0x89;
public const int VK_DEAD_CARON = 0x8a;
public const int VK_DEAD_CEDILLA = 0x8b;
public const int VK_DEAD_OGONEK = 0x8c;
public const int VK_DEAD_IOTA = 0x8d;
public const int VK_DEAD_VOICED_SOUND = 0x8e;
public const int VK_DEAD_SEMIVOICED_SOUND = 0x8f;
public const int VK_AMPERSAND = 0x96;
public const int VK_ASTERISK = 0x97;
public const int VK_QUOTEDBL = 0x98;
public const int VK_LESS = 0x99;
public const int VK_GREATER = 0xa0;
public const int VK_BRACELEFT = 0xa1;
public const int VK_BRACERIGHT = 0xa2;
public const int VK_AT = 0x0200;
public const int VK_COLON = 0x0201;
public const int VK_CIRCUMFLEX = 0x0202;
public const int VK_DOLLAR = 0x0203;
public const int VK_EURO_SIGN = 0x0204;
public const int VK_EXCLAMATION_MARK = 0x0205;
public const int VK_INVERTED_EXCLAMATION_MARK = 0x0206;
public const int VK_LEFT_PARENTHESIS = 0x0207;
public const int VK_NUMBER_SIGN = 0x0208;
public const int VK_PLUS = 0x0209;
public const int VK_RIGHT_PARENTHESIS = 0x020A;
public const int VK_UNDERSCORE = 0x020B;
public const int VK_WINDOWS = 0x020C;
public const int VK_CONTEXT_MENU = 0x020D;
public const int VK_const = 0x0018;
public const int VK_CONVERT = 0x001C;
public const int VK_NONCONVERT = 0x001D;
public const int VK_ACCEPT = 0x001E;
public const int VK_MODECHANGE = 0x001F;
public const int VK_KANA = 0x0015;
public const int VK_KANJI = 0x0019;
public const int VK_ALPHANUMERIC = 0x00F0;
public const int VK_KATAKANA = 0x00F1;
public const int VK_HIRAGANA = 0x00F2;
public const int VK_FULL_WIDTH = 0x00F3;
public const int VK_HALF_WIDTH = 0x00F4;
public const int VK_ROMAN_CHARACTERS = 0x00F5;
public const int VK_ALL_CANDIDATES = 0x0100;
public const int VK_PREVIOUS_CANDIDATE = 0x0101;
public const int VK_CODE_INPUT = 0x0102;
public const int VK_JAPANESE_KATAKANA = 0x0103;
public const int VK_JAPANESE_HIRAGANA = 0x0104;
public const int VK_JAPANESE_ROMAN = 0x0105;
public const int VK_KANA_LOCK = 0x0106;
public const int VK_INPUT_METHOD_ON_OFF = 0x0107;
public const int VK_CUT = 0xFFD1;
public const int VK_COPY = 0xFFCD;
public const int VK_PASTE = 0xFFCF;
public const int VK_UNDO = 0xFFCB;
public const int VK_AGAIN = 0xFFC9;
public const int VK_FIND = 0xFFD0;
public const int VK_PROPS = 0xFFCA;
public const int VK_STOP = 0xFFC8;
public const int VK_COMPOSE = 0xFF20;
public const int VK_ALT_GRAPH = 0xFF7E;
public const int VK_BEGIN = 0xFF58;
public const int VK_UNDEFINED = 0x0;
public const int KEY_LOCATION_UNKNOWN = 0;
public const int KEY_LOCATION_STANDARD = 1;
public const int KEY_LOCATION_LEFT = 2;
public const int KEY_LOCATION_RIGHT = 3;
public const int KEY_LOCATION_NUMPAD = 4;
public static readonly char CHAR_UNDEFINED = (char) 0xFFFF;
public const int MOUSE_FIRST = 500;
public const int MOUSE_LAST = 507;
public const int MOUSE_CLICKED = MOUSE_FIRST;
public const int MOUSE_PRESSED = 1 + MOUSE_FIRST; //Event.MOUSE_DOWN
public const int MOUSE_RELEASED = 2 + MOUSE_FIRST; //Event.MOUSE_UP
public const int MOUSE_MOVED = 3 + MOUSE_FIRST; //Event.MOUSE_MOVE
public const int MOUSE_ENTERED = 4 + MOUSE_FIRST; //Event.MOUSE_ENTER
public const int MOUSE_EXITED = 5 + MOUSE_FIRST; //Event.MOUSE_EXIT
public const int MOUSE_DRAGGED = 6 + MOUSE_FIRST; //Event.MOUSE_DRAG
public const int MOUSE_WHEEL = 7 + MOUSE_FIRST;
public const int NOBUTTON = 0;
public const int BUTTON1 = 1;
public const int BUTTON2 = 2;
public const int BUTTON3 = 3;
}
#pragma warning restore 1591
}

View File

@ -0,0 +1,77 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.peer;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MessageEvent is sent to <see cref="TeamRobot.OnMessageReceived(MessageEvent)"/>
/// when a teammate sends a message to your robot.
/// You can use the information contained in this event to determine what to do.
/// </summary>
[Serializable]
public sealed class MessageEvent : Event
{
private const int DEFAULT_PRIORITY = 75;
private readonly string sender;
[NonSerialized]
private readonly object message;
/// <summary>
/// Called by the game to create a new MessageEvent.
/// </summary>
public MessageEvent(string sender, object message)
{
this.sender = sender;
this.message = message;
}
/// <summary>
/// Returns the name of the sending robot.
/// </summary>
public string Sender
{
get { return sender; }
}
/// <summary>
/// Returns the message itself.
/// </summary>
public object Message
{
get { return message; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsTeamRobot())
{
ITeamEvents listener = ((ITeamRobot) robot).GetTeamEventListener();
if (listener != null)
{
listener.OnMessageReceived(this);
}
}
}
internal override byte SerializationType
{
get { throw new System.Exception("Serialization of event type not supported"); }
}
}
}
//doc

View File

@ -0,0 +1,103 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseClickedEvent is sent to <see cref="Robot.OnMouseClicked(MouseEvent)"/>
/// when the mouse is clicked inside the battle view.
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseClickedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseClickedEvent.
/// </summary>
public MouseClickedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseClicked(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseClickedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseClickedEvent) objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseClickedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,103 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseDraggedEvent is sent to <see cref="Robot.OnMouseDragged(MouseEvent)"/>
/// when the mouse is dragged inside the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseDraggedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MouseDraggedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseDragged(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseDraggedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseDraggedEvent) objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseDraggedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,104 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseEnteredEvent is sent to <see cref="Robot.OnMouseEntered(MouseEvent)"/>
/// when the mouse has entered the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseEnteredEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MouseEnteredEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseEntered(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseEnteredEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseEnteredEvent)objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseEnteredEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,91 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
namespace Robocode
{
/// <summary>
/// Super class of all events that originates from the mouse.
/// </summary>
[Serializable]
public abstract class MouseEvent : Event
{
private readonly int button;
private readonly int clickCount;
private readonly int x;
private readonly int y;
private readonly int id;
private readonly int modifiersEx;
private readonly long when;
/// <summary>
/// Called by the game to create a new MouseEvent.
/// </summary>
protected MouseEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
{
this.button = button;
this.clickCount = clickCount;
this.x = x;
this.y = y;
this.id = id;
this.modifiersEx = modifiersEx;
this.when = when;
}
/// <summary>
/// Number of the button
/// </summary>
public int Button
{
get { return button; }
}
/// <summary>
/// Click count
/// </summary>
public int ClickCount
{
get { return clickCount; }
}
/// <summary>
/// Cursor coordinates
/// </summary>
public int X
{
get { return x; }
}
/// <summary>
/// Cursor coordinates
/// </summary>
public int Y
{
get { return y; }
}
internal int ID
{
get { return id; }
}
internal int ModifiersEx
{
get { return modifiersEx; }
}
/// <summary>
/// Age of the event
/// </summary>
public long When
{
get { return when; }
}
}
}
//doc

View File

@ -0,0 +1,103 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseExitedEvent is sent to <see cref="Robot.OnMouseExited(MouseEvent)"/>
/// when the mouse has exited the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseExitedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MouseExitedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseExited(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseExitedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseExitedEvent)objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseExitedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,104 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Drawing;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseMovedEvent is sent to <see cref="Robot.OnMouseMoved(MouseEvent)"/>
/// when the mouse has moved inside the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseMovedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MouseMovedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseMoved(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseMovedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseMovedEvent)objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseMovedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,105 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Drawing;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MousePressedEvent is sent to <see cref="Robot.OnMousePressed(MouseEvent)"/>
/// when the mouse is pressed inside the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MousePressedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MousePressedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMousePressed(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MousePressedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MousePressedEvent)objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MousePressedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,104 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseReleasedEvent is sent to <see cref="Robot.OnMouseReleased(MouseEvent)"/>
/// when the mouse is released inside the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// <seealso cref="MouseWheelMovedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseReleasedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
/// <summary>
/// Called by the game to create a new MouseDraggedEvent.
/// </summary>
public MouseReleasedEvent(int button, int clickCount, int x, int y, int id, int modifiersEx, long when)
: base(button, clickCount, x, y, id, modifiersEx, when)
{
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseReleased(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseReleasedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 6*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseReleasedEvent)objec;
serializer.serialize(buffer, obj.Button);
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int button = buffer.getInt();
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseReleasedEvent(button, clickCount, x, y, id, modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,134 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A MouseWheelMovedEvent is sent to <see cref="Robot.OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// when the mouse wheel is rotated inside the battle view.
/// <seealso cref="MouseClickedEvent"/>
/// <seealso cref="MousePressedEvent"/>
/// <seealso cref="MouseReleasedEvent"/>
/// <seealso cref="MouseEnteredEvent"/>
/// <seealso cref="MouseExitedEvent"/>
/// <seealso cref="MouseMovedEvent"/>
/// <seealso cref="MouseDraggedEvent"/>
/// </summary>
[Serializable]
public sealed class MouseWheelMovedEvent : MouseEvent
{
private const int DEFAULT_PRIORITY = 98;
private readonly int scrollType;
private readonly int scrollAmount;
private readonly int wheelRotation;
/// <summary>
/// Called by the game to create a new MouseWheelMovedEvent.
/// </summary>
public MouseWheelMovedEvent(int clickCount, int x, int y, int scrollType, int scrollAmount, int wheelRotation,
int id, int modifiersEx, long when)
: base(-1, clickCount, x, y, id, modifiersEx, when)
{
this.scrollType = scrollType;
this.scrollAmount = scrollAmount;
this.wheelRotation = wheelRotation;
}
internal int ScrollType
{
get { return scrollType; }
}
internal int ScrollAmount
{
get { return scrollAmount; }
}
/// <summary>
/// Indicates how far the mouse wheel was rotated.
/// </summary>
public int WheelRotation
{
get { return wheelRotation; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsInteractiveRobot())
{
IInteractiveEvents listener = ((IInteractiveRobot) robot).GetInteractiveEventListener();
if (listener != null)
{
listener.OnMouseWheelMoved(this);
}
}
}
internal override byte SerializationType
{
get { return RbSerializerN.MouseWheelMovedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 8*RbSerializerN.SIZEOF_INT + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (MouseWheelMovedEvent) objec;
serializer.serialize(buffer, obj.ClickCount);
serializer.serialize(buffer, obj.X);
serializer.serialize(buffer, obj.Y);
serializer.serialize(buffer, obj.ScrollType);
serializer.serialize(buffer, obj.ScrollAmount);
serializer.serialize(buffer, obj.WheelRotation);
serializer.serialize(buffer, obj.ID);
serializer.serialize(buffer, obj.ModifiersEx);
serializer.serialize(buffer, obj.When);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int clickCount = buffer.getInt();
int x = buffer.getInt();
int y = buffer.getInt();
int scrollType = buffer.getInt();
int scrollAmount = buffer.getInt();
int wheelRotation = buffer.getInt();
int id = buffer.getInt();
int modifiersEx = buffer.getInt();
long when = buffer.getLong();
return new MouseWheelMovedEvent(clickCount, x, y, scrollType, scrollAmount, wheelRotation, id,
modifiersEx, when);
}
}
}
}
//doc

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// A prebuilt condition you can use that indicates your robot has finished moving.
/// <seealso cref="Condition"/>
/// </summary>
public class MoveCompleteCondition : Condition
{
private readonly AdvancedRobot robot;
/// <summary>
/// Creates a new MoveCompleteCondition with default priority.
/// The default priority is 80.
/// </summary>
/// <param name="robot">Your robot, which must be a <see cref="AdvancedRobot"/></param>
public MoveCompleteCondition(AdvancedRobot robot)
{
this.robot = robot;
}
/// <summary>
/// Creates a new MoveCompleteCondition with the specified priority.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// <seealso cref="Condition.Priority"/>
/// </summary>
/// <param name="robot">Your robot, which must be a <see cref="AdvancedRobot"/></param>
/// <param name="priority">The priority of this condition</param>
public MoveCompleteCondition(AdvancedRobot robot, int priority)
{
this.robot = robot;
this.priority = priority;
}
/// <summary>
/// Tests if the robot has stopped moving.
/// Returns true if the robot has stopped moving
/// </summary>
public override bool Test()
{
return (robot.DistanceRemaining == 0);
}
}
}
//doc

View File

@ -0,0 +1,50 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.peer;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// This event occurs when your robot should paint, where the
/// <see cref="Robot.OnPaint(IGraphics)"/> is called on your robot.
/// <p/>
/// You can use this event for setting the event priority by calling
/// <see cref="AdvancedRobot.SetEventPriority(string, int)"/>
/// </summary>
[Serializable]
public sealed class PaintEvent : Event
{
private const int DEFAULT_PRIORITY = 5;
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsPaintRobot())
{
IPaintEvents listener = ((IPaintRobot) robot).GetPaintEventListener();
if (listener != null)
{
listener.OnPaint(graphics);
}
}
}
internal override byte SerializationType
{
get { throw new System.Exception("Serialization of this type is not supported"); }
}
}
}
//doc

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// A prebuilt condition you can use that indicates your radar has finished turning.
/// <seealso cref="Condition"/>
/// </summary>
public class RadarTurnCompleteCondition : Condition
{
private readonly AdvancedRobot robot;
/// <summary>
/// Creates a new RadarTurnCompleteCondition with default priority.
/// The default priority is 80.
/// </summary>
/// <param name="robot">Your robot, which must be a <see cref="AdvancedRobot"/></param>
public RadarTurnCompleteCondition(AdvancedRobot robot)
{
this.robot = robot;
}
/// <summary>
/// Creates a new RadarTurnCompleteCondition with the specified priority.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// <seealso cref="Condition.Priority"/>
/// </summary>
/// <param name="robot">Your robot, which must be a <see cref="AdvancedRobot"/></param>
/// <param name="priority">The priority of this condition</param>
public RadarTurnCompleteCondition(AdvancedRobot robot, int priority)
{
this.robot = robot;
this.priority = priority;
}
/// <summary>
/// Tests if the radar has stopped turning.
/// Returns true if the radar has stopped turning; false otherwise
/// </summary>
public override bool Test()
{
return (robot.RadarTurnRemaining == 0);
}
}
}
//doc

View File

@ -0,0 +1,364 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using Robocode.Util;
namespace Robocode
{
/// <summary>
/// This advanced robot type allows you to set a rate for each of the robot's movements.
/// <p />
/// You can set the rate for:
/// <ul>
/// <li>velocity - pixels per turn</li>
/// <li>robot turn - radians per turn</li>
/// <li>gun rotation - radians per turn</li>
/// <li>radar rotation - radians per turn</li>
/// </ul>
/// When you set a rate for one of the above movements, the movement will continue the move by
/// specified rate for ever, until the rate is changed. In order to move ahead or right, the
/// rate must be set to a positive value. If a negative value is used instead, the movement
/// will go back or to the left. In order to stop the movement, the rate must be
/// set to 0.
/// <para />
/// Note: When calling <see cref="VelocityRate" />, <see cref="TurnRate" />,
/// <see cref="GunRotationRate" />, <see cref="RadarRotationRate" /> and variants,
/// any previous calls to "movement" functions outside of <see cref="RateControlRobot" />,
/// such as <see cref="AdvancedRobot.SetAhead(double)" />,
/// <see cref="AdvancedRobot.SetTurnLeft(double)" />,
/// <see cref="AdvancedRobot.SetTurnRadarRightRadians(double)" /> and similar will be
/// overridden when calling the <see cref="Execute()" /> on this robot class.
/// <p />
/// Look into the source code for the samplecs.VelociRobot in order to see how to use this
/// robot type.
/// <seealso cref="JuniorRobot"/>
/// <seealso cref="Robot"/>
/// <seealso cref="AdvancedRobot"/>
/// <seealso cref="TeamRobot"/>
/// <seealso cref="IDroid"/>
/// <seealso cref="IBorderSentry"/>
/// </summary>
public abstract class RateControlRobot : TeamRobot
{
private double velocityRate; // Pixels per turn
private double turnRate; // Radians per turn
private double gunRotationRate; // Radians per turn
private double radarRotationRate; // Radians per turn
///
///<summary>
/// The speed the robot will move (forward), in pixels per turn.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the robot will move backwards
/// <p />
/// <example>
/// <code>
/// // Set the robot to move forward 2 pixels per turn
/// VelocityRate = 2;
///
/// // Set the robot to move backwards 8 pixels per turn
/// // (overrides the previous order)
/// VelocityRate = -8;
///
/// ...
/// // Executes the last VelocityRate
/// Execute();
/// </code>
/// </example>
/// Note: This method overrules <see cref="AdvancedRobot.SetAhead(double)" /> and
/// <see cref="AdvancedRobot.SetBack(double)" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="TurnRate" />
/// <seealso cref="GunRotationRate" />
/// <seealso cref="RadarRotationRate" />
/// <seealso cref="AdvancedRobot.SetAhead(double)" />
/// <seealso cref="AdvancedRobot.SetBack(double)" />
///</summary>
public double VelocityRate
{
get { return velocityRate; }
set { velocityRate = value; }
}
///
///<summary>
/// The robot's clockwise (right) rotation per turn, in degrees.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the robot turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the robot to turn right 10 degrees per turn
/// TurnRate = 10;
///
/// // Set the robot to turn left 4 degrees per turn
/// // (overrides the previous order)
/// TurnRate = -5;
///
/// ...
/// // Executes the last TurnRate
/// Execute();
/// </code>
/// </example>
/// <seealso cref="TurnRate" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="GunRotationRate" />
/// <seealso cref="RadarRotationRate" />
/// <seealso cref="AdvancedRobot.SetTurnRight(double)" />
/// <seealso cref="AdvancedRobot.SetTurnLeft(double)" />
///</summary>
public double TurnRate
{
get { return Utils.ToRadians(turnRate); }
set { turnRate = Utils.ToRadians(value); }
}
/// <summary>
/// The robot's clockwise (right) rotation per turn, in radians.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the robot turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the robot to turn right pi / 32 radians per turn
/// TurnRateRadians = Math.PI / 32;
///
/// // Set the robot to turn left pi / 20 radians per turn
/// // (overrides the previous order)
/// TurnRateRadians = -Math.PI / 20;
///
/// ...
/// // Executes the last TurnRateRadians
/// Execute();
/// </code>
/// </example>
///
/// <seealso cref="TurnRateRadians" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="GunRotationRateRadians" />
/// <seealso cref="RadarRotationRateRadians" />
/// <seealso cref="AdvancedRobot.SetTurnRightRadians(double)" />
/// <seealso cref="AdvancedRobot.SetTurnLeftRadians(double)" />
/// </summary>
public double TurnRateRadians
{
get { return turnRate; }
set { turnRate = value; }
}
/// <summary>
/// The gun's clockwise (right) rotation per turn, in degrees.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the gun turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the gun to turn right 15 degrees per turn
/// GunRotationRate = 15;
///
/// // Set the gun to turn left 9 degrees per turn
/// // (overrides the previous order)
/// GunRotationRate = -9;
///
/// ...
/// // Executes the last GunRotationRate()
/// Execute();
/// </code>
/// </example>
/// <seealso cref="GunRotationRate" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="TurnRate" />
/// <seealso cref="RadarRotationRate" />
/// <seealso cref="AdvancedRobot.SetTurnGunRight(double)" />
/// <seealso cref="AdvancedRobot.SetTurnGunLeft(double)" />
/// </summary>
public double GunRotationRate
{
get { return Utils.ToDegrees(gunRotationRate); }
set { gunRotationRate = Utils.ToRadians(value); }
}
/// <summary>
/// The gun's clockwise (right) rotation per turn, in radians.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the gun turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the gun to turn right pi / 16 radians per turn
/// GunRotationRateRadians = Math.PI / 16;
///
/// // Set the gun to turn left pi / 12 radians per turn
/// // (overrides the previous order)
/// GunRotationRateRadians = -Math.PI / 12;
///
/// ...
/// // Executes the last GunRotationRateRadians
/// Execute();
/// </code>
/// </example>
/// <seealso cref="GunRotationRateRadians()" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="TurnRateRadians" />
/// <seealso cref="RadarRotationRateRadians" />
/// <seealso cref="AdvancedRobot.SetTurnGunRightRadians(double)" />
/// <seealso cref="AdvancedRobot.SetTurnGunLeftRadians(double)" />
/// </summary>
public double GunRotationRateRadians
{
get { return gunRotationRate; }
set { gunRotationRate = value; }
}
/// <summary>
/// The radar's clockwise (right) rotation per turn, in degrees.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the radar turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the radar to turn right 45 degrees per turn
/// RadarRotationRate = 45;
///
/// // Set the radar to turn left 15 degrees per turn
/// // (overrides the previous order)
/// RadarRotationRate = -15;
///
/// ...
/// // Executes the last RadarRotationRate
/// Execute();
/// </code>
/// </example>
/// <seealso cref="RadarRotationRate()" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="TurnRate" />
/// <seealso cref="GunRotationRate" />
/// <seealso cref="AdvancedRobot.SetTurnRadarRight(double)" />
/// <seealso cref="AdvancedRobot.SetTurnRadarLeft(double)" />
/// </summary>
public double RadarRotationRate
{
get { return Utils.ToDegrees(radarRotationRate); }
set { radarRotationRate = Utils.ToRadians(value); }
}
/// <summary>
/// The radar's clockwise (right) rotation per turn, in radians.
/// <p />
/// This call returns immediately, and will not execute until you call
/// Execute() or take an action that executes.
/// <p />
/// Note that both positive and negative values can be given as input,
/// where negative values means that the radar turns counterclockwise (left)
/// <p />
/// <example>
/// <code>
/// // Set the radar to turn right pi / 4 radians per turn
/// RadarRotationRateRadians = Math.PI / 4;
///
/// // Set the radar to turn left pi / 8 radians per turn
/// // (overrides the previous order)
/// RadarRotationRateRadians = -Math.PI / 8;
///
/// ...
/// // Executes the last RadarRotationRateRadians
/// Execute();
/// </code>
/// </example>
/// <seealso cref="RadarRotationRateRadians" />
/// <seealso cref="VelocityRate" />
/// <seealso cref="TurnRateRadians" />
/// <seealso cref="GunRotationRateRadians" />
/// <seealso cref="AdvancedRobot.SetTurnRadarRightRadians(double)" />
/// <seealso cref="AdvancedRobot.SetTurnRadarLeftRadians(double)" />
/// </summary>
public double RadarRotationRateRadians
{
get { return radarRotationRate; }
set { radarRotationRate = value; }
}
///<summary>
/// Executes any pending actions, or continues executing actions that are
/// in process. This call returns after the actions have been started.
/// <p />
/// Note that advanced robots <em>must</em> call this function in order to
/// Execute pending set* calls like e.g. <see cref="VelocityRate" />,
/// <see cref="AdvancedRobot.SetFire(double)" />, <see cref="TurnRate" />
/// etc. Otherwise, these calls will never get executed.
/// <p />
/// Any previous calls to "movement" functions outside of
/// <see cref="RateControlRobot" />, such as
/// <see cref="AdvancedRobot.SetAhead(double)" />,
/// <see cref="AdvancedRobot.SetTurnLeft(double)" />,
/// <see cref="AdvancedRobot.SetTurnRadarLeftRadians(double)" />
/// etc. will be overridden when this method is called on this robot class.
/// <p />
/// <example>
/// In this example the robot will move while turning:
/// <code>
/// VelocityRate = 6;
/// TurnRate = 7;
///
/// while (true)
/// {
/// Execute();
/// }
/// </code>
/// </example>
///</summary>
public override void Execute()
{
MaxVelocity = velocityRate;
if (velocityRate > 0)
{
SetAhead(Double.PositiveInfinity);
}
else if (velocityRate < 0)
{
SetBack(Double.PositiveInfinity);
}
else
{
SetAhead(0);
}
SetTurnGunRightRadians(gunRotationRate);
SetTurnRadarRightRadians(radarRotationRate);
SetTurnRightRadians(turnRate);
base.Execute();
}
}
}
//doc

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,95 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Drawing;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// This event is sent to <see cref="Robot.OnRobotDeath(RobotDeathEvent)"/>
/// when another robot (not your robot) dies.
/// </summary>
[Serializable]
public sealed class RobotDeathEvent : Event
{
private const int DEFAULT_PRIORITY = 70;
private readonly string robotName;
/// <summary>
/// Called by the game to create a new RobotDeathEvent.
/// </summary>
/// <param name="robotName">the name of the robot that died</param>
public RobotDeathEvent(string robotName)
{
this.robotName = robotName;
}
/// <summary>
/// Returns the name of the robot that died.
/// </summary>
public string Name
{
get { return robotName; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnRobotDeath(this);
}
}
internal override byte SerializationType
{
get { return RbSerializerN.RobotDeathEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (RobotDeathEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + serializer.sizeOf(obj.robotName);
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (RobotDeathEvent) objec;
serializer.serialize(buffer, obj.robotName);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
string name = serializer.deserializeString(buffer);
return new RobotDeathEvent(name);
}
}
}
}
//doc

View File

@ -0,0 +1,401 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.security;
using net.sf.robocode.serialization;
using Robocode.Util;
namespace Robocode
{
/// <summary>
/// Contains the status of a robot for a specific time/turn returned by
/// <see cref="StatusEvent.Status"/>.
/// </summary>
[Serializable]
public sealed class RobotStatus
{
private readonly double energy;
private readonly double x;
private readonly double y;
private readonly double bodyHeading;
private readonly double gunHeading;
private readonly double radarHeading;
private readonly double velocity;
private readonly double bodyTurnRemaining;
private readonly double radarTurnRemaining;
private readonly double gunTurnRemaining;
private readonly double distanceRemaining;
private readonly double gunHeat;
private readonly int others;
private readonly int numSentries;
private readonly int roundNum;
private readonly int numRounds;
private readonly long time;
/// <summary>
/// Returns the robot's current energy.
/// </summary>
public double Energy
{
get { return energy; }
}
/// <summary>
/// Returns the X position of the robot. (0,0) is at the bottom left of the
/// battlefield.
/// </summary>
/// <seealso cref="Y"/>
public double X
{
get { return x; }
}
/// <summary>
/// Returns the Y position of the robot. (0,0) is at the bottom left of the
/// battlefield.
/// <seealso cref="X"/>
/// </summary>
public double Y
{
get { return y; }
}
/// <summary>
/// Returns the direction that the robot's body is facing, in radians.
/// The value returned will be between 0 and 2 * PI (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// PI / 2 means East, PI means South, and 3 * PI / 2 means West.
/// </summary>
public double HeadingRadians
{
get { return bodyHeading; }
}
/// <summary>
/// Returns the direction that the robot's body is facing, in degrees.
/// The value returned will be between 0 and 360 (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// 90 means East, 180 means South, and 270 means West.
/// </summary>
public double Heading
{
get { return Utils.ToDegrees(bodyHeading); }
}
/// <summary>
/// Returns the direction that the robot's gun is facing, in radians.
/// The value returned will be between 0 and 2 * PI (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// PI / 2 means East, PI means South, and 3 * PI / 2 means West.
/// </summary>
public double GunHeadingRadians
{
get { return gunHeading; }
}
/// <summary>
/// Returns the direction that the robot's gun is facing, in degrees.
/// The value returned will be between 0 and 360 (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// 90 means East, 180 means South, and 270 means West.
/// </summary>
public double GunHeading
{
get { return Utils.ToDegrees(gunHeading); }
}
/// <summary>
/// Returns the direction that the robot's radar is facing, in radians.
/// The value returned will be between 0 and 2 * PI (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// PI / 2 means East, PI means South, and 3 * PI / 2 means West.
/// </summary>
public double RadarHeadingRadians
{
get { return radarHeading; }
}
/// <summary>
/// Returns the direction that the robot's radar is facing, in degrees.
/// The value returned will be between 0 and 360 (is excluded).
/// <p/>
/// Note that the heading in Robocode is like a compass, where 0 means North,
/// 90 means East, 180 means South, and 270 means West.
/// </summary>
public double RadarHeading
{
get { return Utils.ToDegrees(radarHeading); }
}
/// <summary>
/// Returns the velocity of the robot measured in pixels/turn.
/// <p/>
/// The maximum velocity of a robot is defined by <see cref="Rules.MAX_VELOCITY"/>
/// (8 pixels / turn).
/// <seealso cref="Rules.MAX_VELOCITY"/>
/// </summary>
public double Velocity
{
get { return velocity; }
}
/// <summary>
/// Returns the angle remaining in the robots's turn, in radians.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the robot is currently turning to the right.
/// Negative values means that the robot is currently turning to the left.
/// </summary>
public double TurnRemainingRadians
{
get { return bodyTurnRemaining; }
}
/// <summary>
/// Returns the angle remaining in the robots's turn, in degrees.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the robot is currently turning to the right.
/// Negative values means that the robot is currently turning to the left.
/// </summary>
public double TurnRemaining
{
get { return Utils.ToDegrees(bodyTurnRemaining); }
}
/// <summary>
/// Returns the angle remaining in the radar's turn, in radians.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the radar is currently turning to the right.
/// Negative values means that the radar is currently turning to the left.
/// </summary>
public double RadarTurnRemainingRadians
{
get { return radarTurnRemaining; }
}
/// <summary>
/// Returns the angle remaining in the radar's turn, in degrees.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the radar is currently turning to the right.
/// Negative values means that the radar is currently turning to the left.
/// </summary>
public double RadarTurnRemaining
{
get { return Utils.ToDegrees(radarTurnRemaining); }
}
/// <summary>
/// Returns the angle remaining in the gun's turn, in radians.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the gun is currently turning to the right.
/// Negative values means that the gun is currently turning to the left.
/// </summary>
public double GunTurnRemainingRadians
{
get { return gunTurnRemaining; }
}
/// <summary>
/// Returns the angle remaining in the gun's turn, in degrees.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the gun is currently turning to the right.
/// Negative values means that the gun is currently turning to the left.
/// </summary>
public double GunTurnRemaining
{
get { return Utils.ToDegrees(gunTurnRemaining); }
}
/// <summary>
/// Returns the distance remaining in the robot's current move measured in
/// pixels.
/// <p/>
/// This call returns both positive and negative values.
/// Positive values means that the robot is currently moving forwards.
/// Negative values means that the robot is currently moving backwards.
/// </summary>
public double DistanceRemaining
{
get { return distanceRemaining; }
}
/// <summary>
/// Returns the current heat of the gun. The gun cannot Fire unless this is
/// 0. (Calls to Fire will succeed, but will not actually Fire unless
/// GetGunHeat() == 0).
/// <p/>
/// The amount of gun heat generated when the gun is fired is
/// 1 + (firePower / 5). Each turn the gun heat drops by the amount returned
/// by <see cref="Robot.GunCoolingRate"/>, which is a battle setup.
/// <p/>
/// Note that all guns are "hot" at the start of each round, where the gun
/// heat is 3.
/// </summary>
/// <seealso cref="Robot.GunCoolingRate"/>
/// <seealso cref="Robot.Fire(double)"/>
/// <seealso cref="Robot.FireBullet(double)"/>
public double GunHeat
{
get { return gunHeat; }
}
/// <summary>
/// Returns how many opponents that are left in the current round.
/// </summary>
public int Others
{
get { return others; }
}
/// <summary>
/// Returns how many sentry robots that are left in the current round.
/// </summary>
public int NumSentries
{
get { return numSentries; }
}
/// <summary>
/// Returns the number of rounds in the current battle.
/// </summary>
/// <seealso cref="RoundNum"/>
public int NumRounds
{
get { return numRounds; }
}
/// <summary>
/// Returns the current round number (0 to <see cref="NumRounds"/> - 1) of
/// the battle.
/// </summary>
/// <seealso cref="NumRounds"/>
public int RoundNum
{
get { return roundNum; }
}
/// <summary>
/// Returns the game time of the round, where the time is equal to the current turn in the round.
/// </summary>
public long Time
{
get { return time; }
}
private RobotStatus(double energy, double x, double y, double bodyHeading, double gunHeading,
double radarHeading,
double velocity, double bodyTurnRemaining, double radarTurnRemaining,
double gunTurnRemaining,
double distanceRemaining, double gunHeat,
int others, int numSentries,
int roundNum, int numRounds, long time)
{
this.energy = energy;
this.x = x;
this.y = y;
this.bodyHeading = bodyHeading;
this.gunHeading = gunHeading;
this.radarHeading = radarHeading;
this.bodyTurnRemaining = bodyTurnRemaining;
this.velocity = velocity;
this.radarTurnRemaining = radarTurnRemaining;
this.gunTurnRemaining = gunTurnRemaining;
this.distanceRemaining = distanceRemaining;
this.gunHeat = gunHeat;
this.others = others;
this.numSentries = numSentries;
this.roundNum = roundNum;
this.numRounds = numRounds;
this.time = time;
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN, IHiddenStatusHelper
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + 12*RbSerializerN.SIZEOF_DOUBLE + 4*RbSerializerN.SIZEOF_INT
+ RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (RobotStatus) objec;
serializer.serialize(buffer, obj.energy);
serializer.serialize(buffer, obj.x);
serializer.serialize(buffer, obj.y);
serializer.serialize(buffer, obj.bodyHeading);
serializer.serialize(buffer, obj.gunHeading);
serializer.serialize(buffer, obj.radarHeading);
serializer.serialize(buffer, obj.velocity);
serializer.serialize(buffer, obj.bodyTurnRemaining);
serializer.serialize(buffer, obj.radarTurnRemaining);
serializer.serialize(buffer, obj.gunTurnRemaining);
serializer.serialize(buffer, obj.distanceRemaining);
serializer.serialize(buffer, obj.gunHeat);
serializer.serialize(buffer, obj.others);
serializer.serialize(buffer, obj.numSentries);
serializer.serialize(buffer, obj.roundNum);
serializer.serialize(buffer, obj.numRounds);
serializer.serialize(buffer, obj.time);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
double energy = buffer.getDouble();
double x = buffer.getDouble();
double y = buffer.getDouble();
double bodyHeading = buffer.getDouble();
double gunHeading = buffer.getDouble();
double radarHeading = buffer.getDouble();
double velocity = buffer.getDouble();
double bodyTurnRemaining = buffer.getDouble();
double radarTurnRemaining = buffer.getDouble();
double gunTurnRemaining = buffer.getDouble();
double distanceRemaining = buffer.getDouble();
double gunHeat = buffer.getDouble();
int others = buffer.getInt();
int numSentries = buffer.getInt();
int roundNum = buffer.getInt();
int numRounds = buffer.getInt();
long time = buffer.getLong();
return new RobotStatus(energy, x, y, bodyHeading, gunHeading, radarHeading, velocity, bodyTurnRemaining,
radarTurnRemaining, gunTurnRemaining, distanceRemaining, gunHeat, others, numSentries,
roundNum, numRounds, time);
}
public RobotStatus createStatus(double energy, double x, double y, double bodyHeading, double gunHeading,
double radarHeading, double velocity, double bodyTurnRemaining,
double radarTurnRemaining, double gunTurnRemaining, double distanceRemaining,
double gunHeat, int others, int numSentries, int roundNum, int numRounds, long time)
{
return new RobotStatus(energy, x, y, bodyHeading, gunHeading, radarHeading, velocity, bodyTurnRemaining,
radarTurnRemaining, gunTurnRemaining, distanceRemaining, gunHeat, others, numSentries,
roundNum, numRounds, time);
}
}
}
}
//doc

View File

@ -0,0 +1,134 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A RoundEndedEvent is sent to <see cref="Robot.OnRoundEnded(RoundEndedEvent)"/> when a round has ended.
/// You can use the information contained in this event to determine which round that has ended.
/// <seealso cref="Robot.OnRoundEnded(RoundEndedEvent)"/>
/// </summary>
public class RoundEndedEvent : Event
{
private const int DEFAULT_PRIORITY = 110; // System event -> cannot be changed!
private readonly int round;
private readonly int turns;
private readonly int totalTurns;
/// <summary>
/// Called by the game to create a new RoundEndedEvent.
/// </summary>
/// <param name="round">The round that has ended (zero-indexed)</param>
/// <param name="turns">The number of turns that this round reached</param>
/// <param name="totalTurns">The total number of turns reached in the battle when this round ended</param>
public RoundEndedEvent(int round, int turns, int totalTurns)
{
this.round = round;
this.turns = turns;
this.totalTurns = totalTurns;
}
/// <value>
/// The round that ended (zero-indexed).
/// </value>
public int Round
{
get { return round; }
}
/// <value>
/// The number of turns that this round reached.
/// </value>
public int Turns
{
get { return turns; }
}
/// <value>
/// The total number of turns reached in the battle when this round ended.
/// </value>
public int TotalTurns
{
get { return totalTurns; }
}
internal override sealed int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
/// <inheritdoc />
public override sealed int Priority
{
get { return DEFAULT_PRIORITY; }
}
internal override sealed void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (robot != null)
{
IBasicEvents3 listener = robot.GetBasicEventListener() as IBasicEvents3;
if (listener != null)
{
listener.OnRoundEnded(this);
}
}
}
internal override sealed bool IsCriticalEvent
{
get { return true; }
}
internal override byte SerializationType
{
get { return RbSerializerN.RoundEndedEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, Object obje)
{
return RbSerializerN.SIZEOF_TYPEINFO + 3*RbSerializerN.SIZEOF_INT;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, Object obje)
{
RoundEndedEvent evnt = (RoundEndedEvent) obje;
serializer.serialize(buffer, evnt.round);
serializer.serialize(buffer, evnt.turns);
serializer.serialize(buffer, evnt.totalTurns);
}
public Object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
int round = serializer.deserializeInt(buffer);
int turns = serializer.deserializeInt(buffer);
int totalTurns = serializer.deserializeInt(buffer);
return new RoundEndedEvent(round, turns, totalTurns);
}
}
}
}
//doc

View File

@ -0,0 +1,214 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using Robocode.Util;
namespace Robocode
{
/// <summary>
/// Constants and methods that defines the rules of Robocode.
/// Constants are used for rules that will not change.
/// Methods are provided for rules that can be changed between battles or which depends
/// on some other factor.
/// </summary>
public static class Rules
{
// Hide the constructor in the docs as it should not be used
/// <summary>
/// The acceleration of a robot, i.e. the increase of velocity when the
/// robot moves forward, which is 1 pixel/turn.
/// </summary>
public static readonly double ACCELERATION = 1;
/// <summary>
/// The deceleration of a robot, i.e. the decrease of velocity when the
/// robot moves backwards (or brakes), which is 2 pixels/turn.
/// </summary>
public static readonly double DECELERATION = 2;
/// <summary>
/// The maximum velocity of a robot, which is 8 pixels/turn.
/// </summary>
public static readonly double MAX_VELOCITY = 8;
/// <summary>
/// The radar scan radius, which is 1200 pixels.
/// Robots which is more than 1200 pixels away cannot be seen on the radar.
/// </summary>
public static readonly double RADAR_SCAN_RADIUS = 1200;
/// <summary>
/// The minimum bullet power, i.e the amount of energy required for firing a
/// bullet, which is 0.1 energy points.
/// </summary>
public static readonly double MIN_BULLET_POWER = 0.1;
/// <summary>
/// The maximum bullet power, i.e. the maximum amount of energy that can be
/// transferred to a bullet when it is fired, which is 3 energy points.
/// </summary>
public static readonly double MAX_BULLET_POWER = 3;
/// <summary>
/// The maximum turning rate of the robot, in degrees, which is
/// 10 degress/turn.
/// Note, that the turn rate of the robot depends on it's velocity.
/// <seealso cref="MAX_TURN_RATE_RADIANS"/>
/// <seealso cref="GetTurnRate(double)"/>
/// <seealso cref="GetTurnRateRadians(double)"/>
/// </summary>
public static readonly double MAX_TURN_RATE = 10;
/// <summary>
/// The maximum turning rate of the robot measured in radians instead of
/// degrees.
///
/// <seealso cref="MAX_TURN_RATE"/>
/// <seealso cref="GetTurnRate(double)"/>
/// <seealso cref="GetTurnRateRadians(double)"/>
/// </summary>
public static readonly double MAX_TURN_RATE_RADIANS = Utils.ToRadians(MAX_TURN_RATE);
/// <summary>
/// The turning rate of the gun measured in degrees, which is 20 degrees/turn.
/// Note, that if AdjustGunForRobotTurn = true has been set, the gun turn is
/// independent of the robot turn. In this case the gun moves relatively to the screen.
/// <p />
/// If AdjustGunForRobotTurn = false has been set or AdjustGunForRobotTurn has not
/// been called at all (this is the default), then the gun turn is dependent on
/// the robot turn, and in this case the gun moves relatively to the robot body.
///
/// <seealso cref="GUN_TURN_RATE_RADIANS"/>
/// <seealso cref="Robot.IsAdjustGunForRobotTurn"/>
/// </summary>
public static readonly double GUN_TURN_RATE = 20;
/// <summary>
/// The turning rate of the gun measured in radians instead of degrees.
///
/// <seealso cref="GUN_TURN_RATE"/>
/// </summary>
public static readonly double GUN_TURN_RATE_RADIANS = Utils.ToRadians(GUN_TURN_RATE);
/// <summary>
/// The turning rate of the radar measured in degrees, which is 45 degrees/turn.
/// Note, that if AdjustRadarForRobotTurn = true and/or
/// AdjustRadarForGunTurn = true has been set, the radar turn is independent of
/// the robot and/or gun turn. If both properties hava been set to true, the radar
/// moves relatively to the screen.
/// <p />
/// If AdjustRadarForRobotTurn = false and/or AdjustRadarForGunTurn = false
/// have been set or not set at all (this is the default), then the radar turn is
/// dependent on the robot and/or gun turn, and in this case the radar moves
/// relatively to the gun and/or robot body.
///
/// <seealso cref="RADAR_TURN_RATE_RADIANS"/>
/// <seealso cref="Robot.IsAdjustGunForRobotTurn"/>
/// <seealso cref="Robot.IsAdjustRadarForGunTurn"/>
/// </summary>
public static readonly double RADAR_TURN_RATE = 45;
/// <summary>
/// The turning rate of the radar measured in radians instead of degrees.
///
/// <seealso cref="RADAR_TURN_RATE"/>
/// </summary>
public static readonly double RADAR_TURN_RATE_RADIANS = Utils.ToRadians(RADAR_TURN_RATE);
/// <summary>
/// The amount of damage taken when a robot hits or is hit by another robot,
/// which is 0.6 energy points.
/// </summary>
public static readonly double ROBOT_HIT_DAMAGE = 0.6;
/// <summary>
/// The amount of bonus given when a robot moving forward hits an opponent
/// robot (ramming), which is 1.2 energy points.
/// </summary>
public static readonly double ROBOT_HIT_BONUS = 1.2;
/// <summary>
/// Returns the turn rate of a robot given a specific velocity measured in
/// degrees/turn.
/// <seealso cref="GetTurnRateRadians(double)"/>
/// </summary>
/// <param name="velocity">The velocity of the robot.</param>
public static double GetTurnRate(double velocity)
{
return MAX_TURN_RATE - 0.75*velocity;
}
/// <summary>
/// Returns the turn rate of a robot given a specific velocity measured in
/// radians/turn.
/// <seealso cref="GetTurnRate(double)"/>
/// </summary>
/// <param name="velocity">the velocity of the robot.</param>
public static double GetTurnRateRadians(double velocity)
{
return Utils.ToRadians(GetTurnRate(velocity));
}
/// <summary>
/// Returns the amount of damage taken when robot hits a wall with a
/// specific velocity.
/// </summary>
/// <param name="velocity"> the velocity of the robot.</param>
public static double GetWallHitDamage(double velocity)
{
return Math.Max(Math.Abs(velocity)/2 - 1, 0);
}
/// <summary>
/// Returns the amount of damage of a bullet given a specific bullet power.
/// </summary>
/// <param name="bulletPower"> the energy power of the bullet.</param>
public static double GetBulletDamage(double bulletPower)
{
double damage = 4*bulletPower;
if (bulletPower > 1)
{
damage += 2*(bulletPower - 1);
}
return damage;
}
/// <summary>
/// Returns the amount of bonus given when a robot's bullet hits an opponent
/// robot given a specific bullet power.
/// </summary>
/// <param name="bulletPower">the energy power of the bullet</param>
public static double GetBulletHitBonus(double bulletPower)
{
return 3*bulletPower;
}
/// <summary>
/// Returns the speed of a bullet given a specific bullet power measured in
/// pixels/turn.
/// </summary>
/// <param name="bulletPower">the energy power of the bullet.</param>
public static double GetBulletSpeed(double bulletPower)
{
bulletPower = Math.Min(Math.Max(bulletPower, MIN_BULLET_POWER), MAX_BULLET_POWER);
return 20 - 3 * bulletPower;
}
/// <summary>
/// Returns the heat produced by firing the gun given a specific bullet power.
/// </summary>
/// <param name="bulletPower">the energy power of the bullet</param>
public static double GetGunHeat(double bulletPower)
{
return 1 + (bulletPower/5);
}
}
}
//doc

View File

@ -0,0 +1,238 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A ScannedRobotEvent is sent to <see cref="Robot.OnScannedRobot(ScannedRobotEvent)"/>
/// OnScannedRobot()} when you scan a robot.
/// You can use the information contained in this event to determine what to do.
/// <p/>
/// <b>Note</b>: You should not inherit from this class in your own event class!
/// The internal logic of this event class might change. Hence, your robot might
/// not work in future Robocode versions, if you choose to inherit from this class.
/// </summary>
public class ScannedRobotEvent : Event
{
private const int DEFAULT_PRIORITY = 10;
private readonly string name;
private readonly double energy;
private readonly double heading;
private readonly double bearing;
private readonly double distance;
private readonly double velocity;
private readonly bool isSentryRobot;
[Obsolete("ScannedRobotEvent() is obsolete.\n" +
"Please use ScannedRobotEvent(string, double, double, double, double, double, bool) instead.")]
internal ScannedRobotEvent()
: this(null, 0, 0, 0, 0, 0, false)
{
}
/// <summary>
/// Called by the game to create a new ScannedRobotEvent.
/// </summary>
/// <param name="name">The name of the scanned robot</param>
/// <param name="energy">The energy of the scanned robot</param>
/// <param name="bearing">The bearing of the scanned robot, in radians</param>
/// <param name="distance">The distance from your robot to the scanned robot</param>
/// <param name="heading">The heading of the scanned robot</param>
/// <param name="velocity">The velocity of the scanned robot</param>
[Obsolete("ScannedRobotEvent(string, double, double, double, double, double) is obsolete.\n" +
"Please use ScannedRobotEvent(string, double, double, double, double, double, bool) instead.")]
public ScannedRobotEvent(string name, double energy, double bearing, double distance, double heading, double velocity) :
this(name, energy, bearing, distance, heading, velocity, false)
{
}
/// <summary>
/// Called by the game to create a new ScannedRobotEvent.
/// </summary>
/// <param name="name">The name of the scanned robot</param>
/// <param name="energy">The energy of the scanned robot</param>
/// <param name="bearing">The bearing of the scanned robot, in radians</param>
/// <param name="distance">The distance from your robot to the scanned robot</param>
/// <param name="heading">The heading of the scanned robot</param>
/// <param name="velocity">The velocity of the scanned robot</param>
/// <param name="isSentryRobot">Flag specifying if the scanned robot is a sentry robot</param>
public ScannedRobotEvent(string name, double energy, double bearing, double distance, double heading, double velocity, bool isSentryRobot)
{
this.name = name;
this.energy = energy;
this.bearing = bearing;
this.distance = distance;
this.heading = heading;
this.velocity = velocity;
this.isSentryRobot = isSentryRobot;
}
/// <summary>
/// Returns the bearing to the robot you scanned, relative to your robot's
/// heading, in degrees (-180 &lt;= getBearing() &lt; 180)
/// </summary>
public double Bearing
{
get { return bearing*180.0/Math.PI; }
}
/// <summary>
/// Returns the bearing to the robot you scanned, relative to your robot's
/// heading, in radians (-PI &lt;= getBearingRadians() &lt; PI)
/// </summary>
public double BearingRadians
{
get { return bearing; }
}
/// <summary>
/// Returns the distance to the robot (your center to his center).
/// </summary>
public double Distance
{
get { return distance; }
}
/// <summary>
/// Returns the energy of the robot.
/// </summary>
public double Energy
{
get { return energy; }
}
/// <summary>
/// Returns the heading of the robot, in degrees (0 &lt;= getHeading() &lt; 360)
/// </summary>
public double Heading
{
get { return heading*180.0/Math.PI; }
}
/// <summary>
/// Returns the heading of the robot, in radians (0 &lt;= getHeading() &lt; 2 * PI)
/// </summary>
public double HeadingRadians
{
get { return heading; }
}
/// <summary>
/// Returns the name of the robot.
/// </summary>
public string Name
{
get { return name; }
}
/// <summary>
/// Returns the velocity of the robot.
/// </summary>
public double Velocity
{
get { return velocity; }
}
/// <summary>
/// <code>true</code> if the scanned robot is a sentry robot; <code>false</code> otherwise.
/// </summary>
public bool IsSentryRobot
{
get { return isSentryRobot; }
}
/// <inheritdoc />
public override sealed int CompareTo(Event evnt)
{
int res = base.CompareTo(evnt);
if (res != 0)
{
return res;
}
// Compare the distance, if the events are ScannedRobotEvents
// The shorter distance to the robot, the higher priority
if (evnt is ScannedRobotEvent)
{
return (int) (Distance - ((ScannedRobotEvent) evnt).Distance);
}
// No difference found
return 0;
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnScannedRobot(this);
}
}
internal override byte SerializationType
{
get { return RbSerializerN.ScannedRobotEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
var obj = (ScannedRobotEvent) objec;
return RbSerializerN.SIZEOF_TYPEINFO + serializer.sizeOf(obj.name) + 5 * RbSerializerN.SIZEOF_DOUBLE + RbSerializerN.SIZEOF_BOOL;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (ScannedRobotEvent) objec;
serializer.serialize(buffer, obj.name);
serializer.serialize(buffer, obj.energy);
serializer.serialize(buffer, obj.heading);
serializer.serialize(buffer, obj.bearing);
serializer.serialize(buffer, obj.distance);
serializer.serialize(buffer, obj.velocity);
serializer.serialize(buffer, obj.isSentryRobot);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
string name = serializer.deserializeString(buffer);
double energy = buffer.getDouble();
double heading = buffer.getDouble();
double bearing = buffer.getDouble();
double distance = buffer.getDouble();
double velocity = buffer.getDouble();
bool isSentryRobot = serializer.deserializeBoolean(buffer);
return new ScannedRobotEvent(name, energy, bearing, distance, heading, velocity, isSentryRobot);
}
}
}
}
//doc

View File

@ -0,0 +1,125 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// A SkippedTurnEvent is sent to <see cref="AdvancedRobot.OnSkippedTurn(SkippedTurnEvent)"/>
/// OnSkippedTurn()} when your robot is forced to skipping a turn.
/// You must take an action every turn in order to participate in the game.
/// <example>
/// <code>
/// Thread.Sleep(1000);
/// </code>
/// will cause many SkippedTurnEvents, because you are not responding to the game.
/// If you receive 30 SkippedTurnEvents, you will be removed from the round.
/// <p/>
/// Instead, you should do something such as:
/// <code>
/// for (int i = 0; i &lt; 30; i++)
/// {
/// DoNothing(); // or perhaps Scan();
/// }
/// </code>
/// </example>
/// <p/>
/// This event may also be generated if you are simply doing too much processing
/// between actions, that is using too much processing power for the calculations
/// etc. in your robot.
/// <seealso cref="AdvancedRobot.OnSkippedTurn(SkippedTurnEvent)"/>
/// <seealso cref="SkippedTurnEvent"/>
/// </summary>
public sealed class SkippedTurnEvent : Event
{
private const int DEFAULT_PRIORITY = 100; // System event -> cannot be changed!;
private readonly long skippedTurn;
/// <summary>
/// Called by the game to create a new SkippedTurnEvent.
/// </summary>
public SkippedTurnEvent(long skippedTurn)
{
this.skippedTurn = skippedTurn;
}
/// <summary>
/// Returns the turn that was skipped.
/// </summary>
public long SkippedTurn
{
get { return skippedTurn; }
}
/// <inheritdoc />
public override int Priority
{
get { return DEFAULT_PRIORITY; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
if (statics.IsAdvancedRobot())
{
IAdvancedEvents listener = ((IAdvancedRobot) robot).GetAdvancedEventListener();
if (listener != null)
{
listener.OnSkippedTurn(this);
}
}
}
internal override bool IsCriticalEvent
{
get { return true; }
}
internal override byte SerializationType
{
get { return RbSerializerN.SkippedTurnEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO + RbSerializerN.SIZEOF_LONG;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
var obj = (SkippedTurnEvent)objec;
serializer.serialize(buffer, obj.skippedTurn);
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
long skippedTurn = buffer.getLong();
return new SkippedTurnEvent(skippedTurn);
}
}
}
}
//doc

View File

@ -0,0 +1,66 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.peer;
using Robocode.RobotInterfaces;
namespace Robocode
{
/// <summary>
/// This event is sent to <see cref="Robot.OnStatus(StatusEvent)"/> every
/// turn in a battle to provide the status of the robot.
/// </summary>
[Serializable]
public sealed class StatusEvent : Event
{
private const int DEFAULT_PRIORITY = 99;
private readonly RobotStatus status;
/// <summary>
/// This constructor is called internally from the game in order to create
/// a new <see cref="RobotStatus"/>.
///
/// </summary>
/// <param name="status">the current states</param>
public StatusEvent(RobotStatus status)
{
this.status = status;
}
/// <summary>
/// Returns the <see cref="RobotStatus"/> at the time defined by <see cref="Robot.Time"/>.
/// <seealso cref="Event.Time"/>
/// </summary>
public RobotStatus Status
{
get { return status; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnStatus(this);
}
}
internal override byte SerializationType
{
get { throw new System.Exception("Serialization of this type is not supported"); }
}
}
}
//doc

View File

@ -0,0 +1,193 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System.Collections.Generic;
using Robocode.RobotInterfaces;
using Robocode.RobotInterfaces.Peer;
namespace Robocode
{
/// <summary>
/// An advanced type of robot that supports sending messages between team
/// mates in a robot team.
/// <p/>
/// If you have not done already, you should create a <see cref="Robot"/> or
/// <see cref="AdvancedRobot"/> first.
/// <seealso cref="JuniorRobot"/>
/// <seealso cref="Robot"/>
/// <seealso cref="AdvancedRobot"/>
/// <seealso cref="RateControlRobot"/>
/// <seealso cref="IDroid"/>
/// <seealso cref="IBorderSentry"/>
/// </summary>
public abstract class TeamRobot : AdvancedRobot, ITeamRobot, ITeamEvents
{
/// <summary>
/// Broadcasts a message to all teammates.
/// <p/>
/// <example>
/// <code>
/// public void Run()
/// {
/// BroadcastMessage("I'm here!");
/// }
/// </code>
/// </example>
/// </summary>
/// <param name="message">The message to broadcast to all teammates
/// if the message could not be broadcasted to the teammates.
/// </param>
/// <seealso cref="IsTeammate(string)"/>
/// <seealso cref="Teammates()"/>
/// <seealso cref="SendMessage(string, object)"/>
public void BroadcastMessage(object message)
{
if (peer != null)
{
((ITeamRobotPeer) peer).BroadcastMessage(message);
}
else
{
UninitializedException();
}
}
/// <summary>
/// Returns a list containing all MessageEvents currently in the robot's queue.
/// You might, for example, call this while processing another event.
/// <p/>
/// <example>
/// <code>
/// foreach (MessageEvent e in GetMessageEvents())
/// {
/// // do something with e
/// }
/// </code>
/// </example>
/// <seealso cref="OnMessageReceived(MessageEvent)"/>
/// <seealso cref="MessageEvent"/>
/// </summary>
public IList<MessageEvent> GetMessageEvents()
{
if (peer != null)
{
return new List<MessageEvent>(((ITeamRobotPeer) peer).GetMessageEvents());
}
UninitializedException();
return null; // never called
}
/// <inheritdoc cref="ITeamRobot.GetTeamEventListener()"/>
ITeamEvents ITeamRobot.GetTeamEventListener()
{
return this; // this robot is listening
}
/// <summary>
/// Returns the names of all teammates, or null there is no teammates.
/// The length of the string array is equal to the number of teammates.
/// <p/>
/// <example>
/// <code>
/// public void Run()
/// {
/// // Prints Out all teammates
/// string[] teammates = GetTeammates();
/// if (teammates != null)
/// {
/// foreach (string member in teammates)
/// {
/// Out.WriteLine(member);
/// }
/// }
/// }
/// </code>
/// </example>
/// <seealso cref="IsTeammate(string)"/>
/// <seealso cref="BroadcastMessage(object)"/>
/// <seealso cref="SendMessage(string, object)"/>
/// </summary>
public string[] Teammates
{
get
{
if (peer != null)
{
return ((ITeamRobotPeer) peer).GetTeammates();
}
UninitializedException();
return null;
}
}
/// <summary>
/// Checks if a given robot name is the name of one of your teammates.
/// <p/>
/// <example>
/// <code>
/// public void OnScannedRobot(ScannedRobotEvent e)
/// {
/// if (IsTeammate(e.Name)
/// {
/// return;
/// }
/// Fire(1);
/// }
/// </code>
/// </example>
/// <seealso cref="Teammates"/>
/// <seealso cref="BroadcastMessage(object)"/>
/// <seealso cref="SendMessage(string, object)"/>
/// </summary>
/// <param name="name">The robot name to check</param>
public bool IsTeammate(string name)
{
if (peer != null)
{
return ((ITeamRobotPeer) peer).IsTeammate(name);
}
UninitializedException();
return false;
}
/// <inheritdoc />
public virtual void OnMessageReceived(MessageEvent evnt)
{
}
/// <summary>
/// Sends a message to one (or more) teammates.
/// <p/>
/// <example>
/// <code>
/// public void Run()
/// {
/// SendMessage("Sample.DroidBot", "I'm here!");
/// }
/// </code>
/// </example>
/// <seealso cref="IsTeammate(string)"/>
/// <seealso cref="Teammates"/>
/// <seealso cref="BroadcastMessage(object)"/>
/// </summary>
/// <param name="name">The name of the intended recipient of the message</param>
/// <param name="message">The message to send</param>
public void SendMessage(string name, object message)
{
if (peer != null)
{
((ITeamRobotPeer) peer).SendMessage(name, message);
}
else
{
UninitializedException();
}
}
}
}
//doc

View File

@ -0,0 +1,134 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using System;
using System.Threading;
using net.sf.robocode.io;
using net.sf.robocode.security;
namespace Robocode
{
/// <summary>
/// Wrapper for .NET Thread, secured according to robocode rules.
/// </summary>
public class Thread
{
private static readonly object syncRoot=new object();
private static int runningCounter;
private readonly System.Threading.Thread thread;
private readonly ParameterizedThreadStart real1;
private readonly ThreadStart real2;
/// <summary>
/// Initializes a new instance of the Thread class
/// </summary>
/// <param name="start">A ThreadStart delegate that represents the methods to be invoked when this thread begins executing.</param>
public Thread(ParameterizedThreadStart start)
{
if (start == null)
{
throw new ArgumentException("start");
}
int id = CheckCount();
real1 = start;
thread = new System.Threading.Thread(main);
string name = (string) AppDomain.CurrentDomain.GetData("robotName");
if (!string.IsNullOrEmpty(name))
{
thread.Name = name + " [" + id + "]";
}
}
/// <summary>
/// Initializes a new instance of the Thread class
/// </summary>
/// <param name="start">A ThreadStart delegate that represents the methods to be invoked when this thread begins executing.</param>
public Thread(ThreadStart start)
{
if (start==null)
{
throw new ArgumentException("start");
}
int id = CheckCount();
real2 = start;
thread = new System.Threading.Thread(main);
string name = (string)AppDomain.CurrentDomain.GetData("robotName");
if (!string.IsNullOrEmpty(name))
{
thread.Name = name + " [" + id + "]";
}
}
private static int CheckCount()
{
lock (syncRoot)
{
if (runningCounter > 5)
{
string message = "Preventing " + HiddenAccessN.GetRobotName() + "from thread creation. You may only create 5 threads at same time.";
LoggerN.logError(message);
LoggerN.WriteLineToRobotsConsole(message);
throw new AccessViolationException(message);
}
runningCounter++;
return runningCounter;
}
}
/// <summary>
/// Blocks the current thread for the specified number of milliseconds.
/// </summary>
public static void Sleep(int millisecondsTimeout)
{
System.Threading.Thread.Sleep(millisecondsTimeout);
}
/// <summary>
/// Causes a thread to be scheduled for execution.
/// </summary>
public void Start(object param)
{
thread.Start(param);
}
/// <summary>
/// Causes a thread to be scheduled for execution.
/// </summary>
public void Start()
{
thread.Start(null);
}
private void main(object param)
{
try
{
if (real1!=null)
{
real1.Invoke(param);
}
real2.Invoke();
}
catch (System.Exception ex)
{
Console.WriteLine("Undandled exception on thread " + thread.Name);
Console.WriteLine(ex);
}
finally
{
lock (syncRoot)
{
runningCounter--;
}
}
}
}
}
//doc

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode
{
/// <summary>
/// A prebuilt condition you can use that indicates your robot has finished turning.
/// </summary>
/// <seealso cref="Condition"/>
public class TurnCompleteCondition : Condition
{
private readonly AdvancedRobot robot;
/// <summary>
/// Creates a new TurnCompleteCondition with default priority.
/// The default priority is 80.
/// </summary>
/// <param name="robot">Your robot, which must be an <see cref="AdvancedRobot"/></param>
public TurnCompleteCondition(AdvancedRobot robot)
{
this.robot = robot;
}
/// <summary>
/// Creates a new TurnCompleteCondition with the specified priority.
/// A condition priority is a value from 0 - 99. The higher value, the
/// higher priority. The default priority is 80.
/// </summary>
/// <param name="robot">Your robot, which must be an <see cref="AdvancedRobot"/></param>
/// <param name="priority">The priority of this condition</param>
/// <seealso cref="Condition.Priority"/>
public TurnCompleteCondition(AdvancedRobot robot, int priority)
{
this.robot = robot;
this.priority = priority;
}
/// <summary>
/// Tests if the robot has finished turning.
/// Returns true if the robot has stopped turning; false otherwise
/// </summary>
public override bool Test()
{
return (robot.TurnRemaining == 0);
}
}
}
//doc

View File

@ -0,0 +1,80 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using net.sf.robocode.nio;
using net.sf.robocode.peer;
using net.sf.robocode.serialization;
using Robocode.RobotInterfaces;
namespace Robocode
{
///<summary>
/// This event is sent to <see cref="Robot.OnWin(WinEvent)"/> when your robot
/// wins the round in a battle.
///</summary>
[Serializable]
public sealed class WinEvent : Event
{
private const int DEFAULT_PRIORITY = 100; // System event -> cannot be changed!;
/// <inheritdoc />
public override int Priority
{
get { return DEFAULT_PRIORITY; }
}
internal override int DefaultPriority
{
get { return DEFAULT_PRIORITY; }
}
internal override void Dispatch(IBasicRobot robot, IRobotStaticsN statics, IGraphics graphics)
{
IBasicEvents listener = robot.GetBasicEventListener();
if (listener != null)
{
listener.OnWin(this);
}
}
internal override bool IsCriticalEvent
{
get { return true; }
}
internal override byte SerializationType
{
get { return RbSerializerN.WinEvent_TYPE; }
}
private static ISerializableHelperN createHiddenSerializer()
{
return new SerializableHelper();
}
private class SerializableHelper : ISerializableHelperN
{
public int sizeOf(RbSerializerN serializer, object objec)
{
return RbSerializerN.SIZEOF_TYPEINFO;
}
public void serialize(RbSerializerN serializer, ByteBuffer buffer, object objec)
{
}
public object deserialize(RbSerializerN serializer, ByteBuffer buffer)
{
return new WinEvent();
}
}
}
}
//doc

View File

@ -0,0 +1,48 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Runtime.Serialization;
namespace Robocode.Exception
{
/// <exclude/>
[Serializable]
public class EventInterruptedException : System.Exception
{
private readonly int priority = int.MinValue;
/// <summary>
/// Used by game
/// </summary>
public EventInterruptedException(int priority)
{
this.priority = priority;
}
/// <summary>
/// Last top priority
/// </summary>
public int Priority
{
get
{
return priority;
}
}
/// <summary>
/// Serialization constructor
/// </summary>
protected EventInterruptedException(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}
}
}
//doc

View File

@ -0,0 +1,45 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System;
using System.Runtime.Serialization;
namespace Robocode.Exception
{
/// <summary>
/// Throw this exception to stop robot
/// </summary>
/// <exclude/>
[Serializable]
public class RobotException : System.Exception
{
/// <summary>
/// Default constructor
/// </summary>
public RobotException()
{
}
/// <summary>
/// Constructor with message
/// </summary>
public RobotException(string s)
: base(s)
{
}
/// <summary>
/// Deserialization constructor
/// </summary>
protected RobotException(SerializationInfo info, StreamingContext context) :
base(info, context)
{
}
}
}
//doc

View File

@ -0,0 +1,52 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// An event interface for receiving advanced robot events with an
/// <see cref="IAdvancedRobot"/>
/// <seealso cref="IAdvancedRobot"/>
/// </summary>
public interface IAdvancedEvents
{
/// <summary>
/// This method is called if the robot is using too much time between
/// actions. When this event occur, the robot's turn is skipped, meaning that
/// it cannot take action anymore in this turn.
/// <p/>
/// If you receive 30 skipped turn event, your robot will be removed from the
/// round and loose the round.
/// <p/>
/// You will only receive this event after taking an action. So a robot in an
/// infinite loop will not receive any events, and will simply be stopped.
/// <p/>
/// No correctly working, reasonable robot should ever receive this event
/// unless it is using too many CPU cycles.
/// <seealso cref="Robocode.SkippedTurnEvent"/>
/// <seealso cref="Robocode.Event"/>
/// </summary>
/// <param name="evnt">The skipped turn event set by the game</param>
void OnSkippedTurn(SkippedTurnEvent evnt);
/// <summary>
/// This method is called when a custom condition is met.
/// <p/>
/// See the sample robots for examples of use, e.g. the Sample.Target
/// robot.
/// <seealso cref="Robocode.AdvancedRobot.AddCustomEvent(Condition)"/>
/// <seealso cref="Robocode.CustomEvent"/>
/// <seealso cref="Robocode.Event"/>
/// </summary>
/// <param name="evnt">The custom event that occurred</param>
void OnCustomEvent(CustomEvent evnt);
}
}
//doc

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode.RobotInterfaces
{
/// <summary>
/// A robot interface for creating a more advanced type of robot like
/// <see cref="Robocode.AdvancedRobot"/> that is able to handle advanced robot events.
/// An advanced robot allows non-blocking calls, custom events, get notifications
/// about skipped turns, and also allow writes to the file system.
/// <seealso cref="Robocode.AdvancedRobot"/>
/// <seealso cref="IBasicRobot"/>
/// <seealso cref="IJuniorRobot"/>
/// <seealso cref="IInteractiveRobot"/>
/// <seealso cref="ITeamRobot"/>
/// </summary>
public interface IAdvancedRobot : IBasicRobot
{
/// <summary>
/// This method is called by the game to notify this robot about advanced
/// robot event. Hence, this method must be implemented so it returns your
/// <see cref="IAdvancedEvents"/> listener.
/// </summary>
IAdvancedEvents GetAdvancedEventListener();
}
}
//doc

View File

@ -0,0 +1,270 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// An event interface for receiving basic robot events with an
/// <see cref="IBasicRobot"/>.
/// <seealso cref="IBasicRobot"/>
/// </summary>
public interface IBasicEvents
{
/// <summary>
/// This method is called every turn in a battle round in order to provide
/// the robot status as a complete snapshot of the robot's current state at
/// that specific time.
/// <p/>
/// The main benefit of this method is that you'll automatically receive all
/// current data values of the robot like e.g. the x and y coordinate,
/// heading, gun heat etc., which are grouped into the exact same time/turn.
/// <p/>
/// This is the only way to map the robots data values to a specific time.
/// For example, it is not possible to determine the exact time of the
/// robot's heading by calling first calling <see cref="Robot.Time"/> and then
/// <see cref="Robot.Heading"/> afterwards, as the time <em>might</em> change
/// after between the <see cref="Robot.Time"/> and <see cref="Robot.Heading"/>
/// call.
/// <seealso cref="StatusEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnStatus(StatusEvent evnt);
/// <summary>
/// This method is called when one of your bullets hits another robot.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// <example>
/// <code>
/// public void OnBulletHit(BulletHitEvent evnt)
/// {
/// Out.WriteLine("I hit " + evnt.Name + "!");
/// }
/// </code>
/// </example>
/// <seealso cref="BulletHitEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnBulletHit(BulletHitEvent evnt);
/// <summary>
/// This method is called when one of your bullets hits another bullet.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// <example>
/// <code>
/// public void OnBulletHitBullet(BulletHitBulletEvent evnt)
/// {
/// Out.WriteLine("I hit a bullet fired by " + evnt.Bullet.Name + "!");
/// }
/// </code>
///</example>
/// <seealso cref="BulletHitBulletEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnBulletHitBullet(BulletHitBulletEvent evnt);
/// <summary>
/// This method is called when one of your bullets misses, i.e. hits a wall.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// <example>
/// <code>
/// public void OnBulletMissed(BulletMissedEvent evnt)
/// {
/// Out.WriteLine("Drat, I missed.");
/// }
/// </code>
///</example>
/// <seealso cref="BulletMissedEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnBulletMissed(BulletMissedEvent evnt);
/// <summary>
/// This method is called if your robot dies.
/// <p/>
/// You should override it in your robot if you want to be informed of this
/// event. Actions will have no effect if called from this section. The
/// intent is to allow you to perform calculations or print something out
/// when the robot is killed.
/// <seealso cref="DeathEvent"/>
/// <seealso cref="WinEvent"/>
/// <seealso cref="BattleEndedEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnDeath(DeathEvent evnt);
/// <summary>
/// This method is called when your robot is hit by a bullet.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// <example>
/// <code>
/// void OnHitByBullet(HitByBulletEvent evnt)
/// {
/// Out.WriteLine(event.RobotName + " hit me!");
/// }
/// </code>
///</example>
/// <seealso cref="HitByBulletEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnHitByBullet(HitByBulletEvent evnt);
/// <summary>
/// This method is called when your robot collides with another robot.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// <example>
/// <code>
/// void OnHitRobot(HitRobotEvent evnt)
/// {
/// if (event.Bearing > -90 &amp;&amp; evnt.Bearing &lt;= 90)
/// {
/// Back(100);
/// }
/// else
/// {
/// Ahead(100);
/// }
/// }
/// </code>
/// -- or perhaps, for a more advanced robot --
/// <code>
/// public void OnHitRobot(HitRobotEvent evnt)
/// {
/// if (event.Bearing > -90 &amp;&amp; evnt.Bearing &lt;= 90)
/// {
/// SetBack(100);
/// }
/// else
/// {
/// SetAhead(100);
/// }
/// }
/// </code>
/// </example>
/// <p/>
/// The angle is relative to your robot's facing. So 0 is straight ahead of
/// you.
/// <p/>
/// This event can be generated if another robot hits you, in which case
/// <see cref="HitRobotEvent.IsMyFault()"/> will return false.
/// In this case, you will not be automatically stopped by the game --
/// but if you continue moving toward the robot you will hit it (and
/// generate another event). If you are moving away, then you won't hit it.
/// <seealso cref="HitRobotEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnHitRobot(HitRobotEvent evnt);
/// <summary>
/// This method is called when your robot collides with a wall.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <p/>
/// The wall at the top of the screen is 0 degrees, right is 90 degrees,
/// bottom is 180 degrees, left is 270 degrees. But this event is relative to
/// your heading, so: The bearing is such that <see cref="Robot.TurnRight(double)"/>
/// <see cref="HitWallEvent.Bearing"/> will point you perpendicular to the wall.
/// <p/>
/// <example>
/// <code>
/// void OnHitWall(HitWallEvent evnt)
/// {
/// Out.WriteLine("Ouch, I hit a wall bearing " + evnt.Bearing + " degrees.");
/// }
/// </code>
/// </example>
/// <seealso cref="HitWallEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnHitWall(HitWallEvent evnt);
/// <summary>
/// This method is called when your robot sees another robot, i.e. when the
/// robot's radar scan "hits" another robot.
/// You should override it in your robot if you want to be informed of this
/// event. (Almost all robots should override this!)
/// <p/>
/// This event is automatically called if there is a robot in range of your
/// radar.
/// <p/>
/// Note that the robot's radar can only see robot within the range defined
/// by <see cref="Rules.RADAR_SCAN_RADIUS"/> (1200 pixels).
/// <p/>
/// Also not that the bearing of the scanned robot is relative to your
/// robot's heading.
/// <p/>
/// <example>
/// <code>
/// void OnScannedRobot(ScannedRobotEvent evnt)
/// {
/// // Assuming radar and gun are aligned...
/// if (event.Distance &lt; 100)
/// {
/// Fire(3);
/// }
/// else
/// {
/// Fire(1);
/// }
/// }
/// </code>
/// </example>
/// <p/>
/// <b>Note:</b><br/>
/// The game assists Robots in firing, as follows:
/// <ul>
/// <li>If the gun and radar are aligned (and were aligned last turn),</li>
/// <li>and the event is current,</li>
/// <li>and you call Fire() before taking any other actions, Robot.Fire(double) will Fire directly at the robot.</li>
/// </ul>
/// <p/>
/// In essence, this means that if you can see a robot, and it doesn't move,
/// then Fire will hit it.
/// <p/>
/// AdvancedRobots will NOT be assisted in this manner, and are expected to
/// examine the event to determine if <see cref="Robot.Fire(double)"/> would
/// hit. (i.e. you are spinning your gun around, but by the time you get the
/// event, your gun is 5 degrees past the robot).
/// <seealso cref="ScannedRobotEvent"/>
/// <seealso cref="Event"/>
/// <seealso cref="Rules.RADAR_SCAN_RADIUS"/>
/// </summary>
void OnScannedRobot(ScannedRobotEvent evnt);
/// <summary>
/// This method is called when another robot dies.
/// You should override it in your robot if you want to be informed of this
/// event.
/// <seealso cref="RobotDeathEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnRobotDeath(RobotDeathEvent evnt);
/// <summary>
/// This method is called if your robot wins a battle.
/// <p/>
/// Your robot could perform a victory dance here! :-)
/// <seealso cref="DeathEvent"/>
/// <seealso cref="BattleEndedEvent"/>
/// <seealso cref="Event"/>
/// </summary>
void OnWin(WinEvent evnt);
}
}
//doc

View File

@ -0,0 +1,38 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// First extended version of the <see cref="IBasicEvents"/> interface.
/// </summary>
public interface IBasicEvents2 : IBasicEvents
{
/// <summary>
/// This method is called after end of the battle, even when the battle is aborted.
/// You should override it in your robot if you want to be informed of this event.
/// <p/>
/// <example>
/// <code>
/// public void OnBattleEnded(BattleEndedEvent evnt)
/// {
/// Out.WriteLine("The battle has ended");
/// }
/// </code>
/// </example>
/// <seealso cref="BattleEndedEvent"/>
/// <seealso cref="Robocode.WinEvent"/>
/// <seealso cref="Robocode.DeathEvent"/>
/// <seealso cref="Robocode.Event"/>
/// </summary>
void OnBattleEnded(BattleEndedEvent evnt);
}
}
//doc

View File

@ -0,0 +1,40 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/

using Robocode;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// Second extended version of the <see cref="IBasicEvents"/> interface.
/// </summary>
public interface IBasicEvents3 : IBasicEvents2
{
/// <summary>
/// This method is called after the end of a round.
/// You should override it in your robot if you want to be informed of this event.
/// <p/>
/// <example>
/// <code>
/// public void OnRoundEnded(RoundEndedEvent event)
/// {
/// Out.WriteLine("The round has ended");
/// }
/// </code>
/// </example>
/// <seealso cref="RoundEndedEvent"/>
/// <seealso cref="IBasicEvents2.OnBattleEnded(BattleEndedEvent)"/>
/// <seealso cref="Robocode.WinEvent"/>
/// <seealso cref="Robocode.DeathEvent"/>
/// <seealso cref="Robocode.Event"/>
/// </summary>
/// <param name="evnt"></param>
void OnRoundEnded(RoundEndedEvent evnt);
}
}

View File

@ -0,0 +1,59 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using System.IO;
using Robocode.RobotInterfaces.Peer;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// A robot interface for creating a basic type of robot like <see cref="Robocode.Robot"/>
/// that is able to receive common robot events, but not interactive events as
/// with the <see cref="Robocode.Robot"/> class.
/// A basic robot allows blocking calls only and cannot handle custom events nor
/// writes to the file system like an advanced robot.
/// <seealso cref="Robocode.Robot"/>
/// <seealso cref="IJuniorRobot"/>
/// <seealso cref="IInteractiveRobot"/>
/// <seealso cref="IAdvancedRobot"/>
/// <seealso cref="ITeamRobot"/>
/// </summary>
public interface IBasicRobot
{
/// <summary>
/// This method is called by the game to invoke the <see cref="IRunnable.Run()"/>
/// method of your robot, where the program of your robot is implemented.
/// </summary>
IRunnable GetRobotRunnable();
/// <summary>
/// This method is called by the game to notify this robot about basic
/// robot event. Hence, this method must be implemented so it returns your
/// <see cref="IBasicEvents"/> listener.
/// </summary>
IBasicEvents GetBasicEventListener();
/// <summary>
/// Do not call this method! Your robot will simply stop interacting with
/// the game.
/// <p/>
/// This method is called by the game. A robot peer is the object that deals
/// with game mechanics and rules, and makes sure your robot abides by them.
/// </summary>
void SetPeer(IBasicRobotPeer peer);
/// <summary>
/// Do not call this method!
/// <p/>
/// This method is called by the game when setting the Out stream for your
/// robot.
/// </summary>
void SetOut(TextWriter output);
}
}
//doc

View File

@ -0,0 +1,183 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
using Robocode;
namespace Robocode.RobotInterfaces
{
/// <summary>
/// An event interface for receiving interactive events with an <see cref="IInteractiveRobot"/>.
/// <seealso cref="IInteractiveRobot"/>
/// </summary>
public interface IInteractiveEvents
{
/// <summary>
/// This method is called when a key has been pressed.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// key events.
/// <seealso cref="OnKeyReleased(KeyEvent)"/>
/// <seealso cref="OnKeyTyped(KeyEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnKeyPressed(KeyEvent evnt);
/// <summary>
/// This method is called when a key has been released.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// key events.
/// <seealso cref="OnKeyPressed(KeyEvent)"/>
/// <seealso cref="OnKeyTyped(KeyEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnKeyReleased(KeyEvent evnt);
/// <summary>
/// This method is called when a key has been typed (pressed and released).
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// key events.
/// <seealso cref="OnKeyPressed(KeyEvent)"/>
/// <seealso cref="OnKeyReleased(KeyEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnKeyTyped(KeyEvent evnt);
/// <summary>
/// This method is called when a mouse button has been clicked (pressed and
/// released).
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseClicked(MouseEvent evnt);
/// <summary>
/// This method is called when the mouse has entered the battle view.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseEntered(MouseEvent evnt);
/// <summary>
/// This method is called when the mouse has exited the battle view.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseExited(MouseEvent evnt);
/// <summary>
/// This method is called when a mouse button has been pressed.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMousePressed(MouseEvent evnt);
/// <summary>
/// This method is called when a mouse button has been released.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseReleased(MouseEvent evnt);
/// <summary>
/// This method is called when the mouse has been moved.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseMoved(MouseEvent evnt);
/// <summary>
/// This method is called when a mouse button has been pressed and then
/// dragged.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseWheelMoved(MouseWheelMovedEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseDragged(MouseEvent evnt);
/// <summary>
/// This method is called when the mouse wheel has been rotated.
/// <p/>
/// See the Sample.Interactive robot for an example of how to use
/// mouse events.
/// <seealso cref="OnMouseMoved(MouseEvent)"/>
/// <seealso cref="OnMousePressed(MouseEvent)"/>
/// <seealso cref="OnMouseReleased(MouseEvent)"/>
/// <seealso cref="OnMouseClicked(MouseEvent)"/>
/// <seealso cref="OnMouseEntered(MouseEvent)"/>
/// <seealso cref="OnMouseExited(MouseEvent)"/>
/// <seealso cref="OnMouseDragged(MouseEvent)"/>
/// </summary>
/// <param name="evnt">Holds details about current event</param>
void OnMouseWheelMoved(MouseWheelMovedEvent evnt);
}
}
//doc

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode.RobotInterfaces
{
/// <summary>
/// A robot interface for creating an interactive type of robot like
/// <see cref="Robocode.Robot"/> and <see cref="Robocode.AdvancedRobot"/> that is able to
/// receive interactive events from the keyboard or mouse.
/// If a robot is directly inherited from this class it will behave as similar to
/// a <see cref="IBasicRobot"/>. If you need it to behave similar to an
/// <see cref="IAdvancedRobot"/> or <see cref="ITeamRobot"/>, you should inherit from these
/// interfaces instead, as these are inherited from this interface.
/// <seealso cref="Robocode.Robot"/>
/// <seealso cref="Robocode.AdvancedRobot"/>
/// <seealso cref="IBasicRobot"/>
/// <seealso cref="IJuniorRobot"/>
/// <seealso cref="IAdvancedRobot"/>
/// <seealso cref="ITeamRobot"/>
/// </summary>
public interface IInteractiveRobot : IBasicRobot
{
/// <summary>
/// This method is called by the game to notify this robot about interactive
/// events, i.e. keyboard and mouse events. Hence, this method must be
/// implemented so it returns your <see cref="IInteractiveEvents"/> listener.
/// </summary>
IInteractiveEvents GetInteractiveEventListener();
}
}
//doc

View File

@ -0,0 +1,38 @@
/**
* Copyright (c) 2001-2016 Mathew A. Nelson and Robocode contributors
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://robocode.sourceforge.net/license/epl-v10.html
*/
namespace Robocode.RobotInterfaces
{
/// <summary>
/// A robot interface for creating the most primitive robot type, which is a
/// <see cref="Robocode.JuniorRobot"/>. A junior robot is simpler than the
/// <see cref="Robocode.Robot"/> class.
/// <p/>
/// A junior robot has a simplified model, in purpose of teaching programming
/// skills to inexperienced in programming students.
/// The simplified robot model will keep player from overwhelming of Robocode's
/// rules, programming syntax and programming concept.
/// <p/>
/// Instead of using getters and setters, public fields are provided for
/// receiving information like the last scanned robot, the coordinate of the
/// robot etc.
/// <p/>
/// All methods on a junior robot are blocking calls, i.e. they do not return
/// before their action has been completed and will at least take one turn to
/// Execute.
/// <seealso cref="Robocode.JuniorRobot"/>
/// <seealso cref="IBasicRobot"/>
/// <seealso cref="IAdvancedRobot"/>
/// <seealso cref="IInteractiveRobot"/>
/// <seealso cref="ITeamRobot"/>
/// </summary>
public interface IJuniorRobot : IBasicRobot
{
}
}
//doc

Some files were not shown because too many files have changed in this diff Show More