Skip to content

Commit

Permalink
Release 1.0.9.
Browse files Browse the repository at this point in the history
  • Loading branch information
exKAZUu committed Sep 5, 2013
1 parent 733c3eb commit 2716b91
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 56 deletions.
20 changes: 20 additions & 0 deletions AppletPageGenerator/AppletPageGenerator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AppletPageGenerator", "AppletPageGenerator\AppletPageGenerator.csproj", "{DBBAE513-38FD-47A0-86CC-681D369AB2B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DBBAE513-38FD-47A0-86CC-681D369AB2B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DBBAE513-38FD-47A0-86CC-681D369AB2B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DBBAE513-38FD-47A0-86CC-681D369AB2B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DBBAE513-38FD-47A0-86CC-681D369AB2B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions AppletPageGenerator/AppletPageGenerator/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
58 changes: 58 additions & 0 deletions AppletPageGenerator/AppletPageGenerator/AppletPageGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DBBAE513-38FD-47A0-86CC-681D369AB2B5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AppletPageGenerator</RootNamespace>
<AssemblyName>AppletPageGenerator</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</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>
-->
</Project>
30 changes: 30 additions & 0 deletions AppletPageGenerator/AppletPageGenerator/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AppletPageGenerator
{
class Program
{
static void Main(string[] args) {
var html = @"
<html>
<body>
<applet archive='Terraforming.jar' code='net/aicomp/terraforming/AppletReplayMain.class' width='100' height='100'>
<param name='fps' value='60'>
<param name='replay' value='replay/XXX'>
</applet>
</body>
</html>
";
var dir = new DirectoryInfo(@"C:\Users\exKAZUu\Projects\ai-comp.github.com\cedec2013\applet\final_replay");
foreach (var repFile in dir.EnumerateFiles("*.rep")) {
var newHtml = html.Replace("XXX", repFile.Name);
File.WriteAllText(@"C:\Users\exKAZUu\Projects\ai-comp.github.com\cedec2013\applet\" + Path.ChangeExtension(repFile.Name, "html"), newHtml);
}
}
}
}
36 changes: 36 additions & 0 deletions AppletPageGenerator/AppletPageGenerator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AppletPageGenerator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AppletPageGenerator")]
[assembly: AssemblyCopyright("Copyright © 2013")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bd4131a4-9d6a-4265-b696-e0e14f42c933")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions CHANGES.jp.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGES
========================

- 2013/08/25 Version 1.0.9
- ロボットの移動量を負の値にするとロボットが増えるバグを修正
- リプレイ機能を追加(-pオプションで指定した.repファイルを再生)
詳細は起動時の-hオプションで表示されるヘルプを御覧ください
- リプレイファイルなどの名前で一桁の数字も二桁になるようパディングを追加

- 2013/08/08 Version 1.0.8
- Maven, SBT の簡易サンプルAIを追加
- 内部的な修正(試合結果の出力方法を変更,リプレイのJSONデータの改善)
Expand Down
2 changes: 1 addition & 1 deletion SampleAI/HeavyJava/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void main(String[] args) {
}
System.out.println("finish");
try {
Thread.sleep(4000);
Thread.sleep(4000000);
} catch (InterruptedException e) {
}
}
Expand Down
8 changes: 8 additions & 0 deletions applet/replay.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<body>
<applet archive="Terraforming.jar" code="net/aicomp/terraforming/AppletReplayMain.class" width="100" height="100">
<param name="fps" value="15">
<param name="replay" value="replay/2013_8_20_4_46_14.rep">
</applet>
</body>
</html>
2 changes: 1 addition & 1 deletion src/main/scala/net/aicomp/terraforming/AppletMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class AppletMain extends Applet {
override def start() {
val fps = allCatch opt getParameter("fps").toDouble getOrElse (15.0)
val user = allCatch opt getParameter("user").toInt getOrElse (1)
Main.main(Array("-l", "-" + Main.USER_PLAYERS, user.toString, "-" + Main.FPS, fps.toString));
Main.main(Array("-" + Main.LIGHT_GUI_MODE, "-" + Main.USER_PLAYERS, user.toString, "-" + Main.FPS, fps.toString));
}
}
13 changes: 13 additions & 0 deletions src/main/scala/net/aicomp/terraforming/AppletReplayMain.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package net.aicomp.terraforming

import java.applet.Applet

import scala.util.control.Exception.allCatch

class AppletReplayMain extends Applet {
override def start() {
val fps = allCatch opt getParameter("fps").toDouble getOrElse (15.0)
val replay = getParameter("replay")
Main.main(Array("-" + Main.LIGHT_GUI_MODE, "-" + Main.REPLAY_MODE, replay, "-" + Main.FPS, fps.toString));
}
}
7 changes: 4 additions & 3 deletions src/main/scala/net/aicomp/terraforming/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ object Main {

def initializeEnvironmentAndScenes(cl: CommandLine) = {
val jss = StreamUtils.openStreamForJavaScript(calendar)
val jsons = StreamUtils.openStreamForJson(calendar)
if (cl.hasOption(CUI_MODE)) {
val env = GameEnvironment()
val scanner = new Scanner(System.in)
Expand All @@ -206,7 +207,7 @@ object Main {
initializeManipulators(cl, env, new ConsoleUserStartManipulator(scanner),
new ConsoleUserGameManipulator(scanner))

val resultScene = new ResultScene(null)
val resultScene = new ResultScene(null, jsons)
val mainScene = new MainScene(resultScene, gameManipulators, jss)
(env, new PlayerScene(mainScene, startManipulators))
} else {
Expand All @@ -216,7 +217,7 @@ object Main {
new GraphicalUserGameManipulator())

val waitScene = new WaitingScene(null) with GraphicalScene
val resultScene = new ResultScene(waitScene) with GraphicalScene
val resultScene = new ResultScene(waitScene, jsons) with GraphicalScene
if (cl.hasOption(RESULT_MODE)) {
val mainScene = new MainScene(resultScene, gameManipulators, jss)
(env, new PlayerScene(mainScene, startManipulators) with GraphicalScene)
Expand Down Expand Up @@ -294,7 +295,7 @@ object Main {

val random = new Random()
val oos = StreamUtils.openStreamForJava(calendar, random)

val field = Field(6, players, random)
env.game = new Game(field, players, 200)
if (userIndices.size == 0) {
Expand Down
26 changes: 12 additions & 14 deletions src/main/scala/net/aicomp/terraforming/scene/ResultScene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import net.aicomp.terraforming.entity.GameEnvironment
import scala.util.Sorting
import java.io.PrintStream

class ResultScene(nextScene: Scene[GameEnvironment]) extends AbstractScene {
class ResultScene(nextScene: Scene[GameEnvironment], stream: PrintStream = null) extends AbstractScene {
var rankString = ""

final override def run() = {
val s1 = "Player 1 (" + game.players(0).name + ") Score: " + game.field.calculateScore(game.players(0))
val s2 = "Player 2 (" + game.players(1).name + ") Score: " + game.field.calculateScore(game.players(1))
val s3 = "Player 3 (" + game.players(2).name + ") Score: " + game.field.calculateScore(game.players(2))
rankString = calculateRank()

displayLine(s1)
displayLine(s2)
displayLine(s3)
Expand All @@ -31,18 +31,16 @@ class ResultScene(nextScene: Scene[GameEnvironment]) extends AbstractScene {
val sortedScores = Sorting.stableSort(scores,
(a: (Int, Int), b: (Int, Int)) => a._2 > b._2 || (a._2 == b._2 && a._1 > b._1))
val id2Rank = sortedScores.zipWithIndex.map { case ((id, score), rank) => (id, rank + 1) }.toMap
var stream: PrintStream = null
try {
stream = new PrintStream("result.txt")
val ret = game.players.map(p => id2Rank(p.id)).mkString(" ")
stream.println(ret)
ret
} catch {
case _: Throwable => ""
} finally {
if (stream != null) {
stream.close()
}
val ranks = game.players.map(p => id2Rank(p.id)).mkString(",")
if (stream != null) {
val names = game.players.map(p => '"' + p.name + '"').mkString(",")
val scores = game.players.map(p => game.field.calculateScore(p)).mkString(",")
stream.print("\"names\":[" + names + "],")
stream.print("\"scores\":[" + scores + "],")
stream.print("\"ranks\":[" + ranks + "]},")
stream.println()
stream.close()
}
ranks
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object DateUtils {
val hour = calendar.get(Calendar.HOUR_OF_DAY)
val minute = calendar.get(Calendar.MINUTE)
val second = calendar.get(Calendar.SECOND)
List(year, month, day, hour, minute, second).mkString("_")
val f = "%02d"
List(year, f.format(month), f.format(day), f.format(hour), f.format(minute), f.format(second)).mkString("_")
}
}
13 changes: 13 additions & 0 deletions src/main/scala/net/aicomp/terraforming/util/misc/StreamUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ object StreamUtils {
case _: Throwable => new PrintStream(new ByteArrayOutputStream())
}
}

def openStreamForJson(calendar: Calendar) = {
try {
new File("replay").mkdir()
val dateForName = DateUtils.dateStringForFileName(calendar)
val fileName = "replay/" + dateForName + ".json"
val ps = new PrintStream(fileName)
ps.print("{\"file\":\"replay/" + dateForName + ".rep\",")
ps
} catch {
case _: Throwable => new PrintStream(new ByteArrayOutputStream())
}
}
}
70 changes: 35 additions & 35 deletions src/test/java/net/aicomp/terraforming/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@ public static void before() throws IOException, InterruptedException {
System.out.println("Finish compiling.");
}

@Test
public void runThreeSampleJavaAIPrograms() {
String command = "java -cp SampleAI/Java Main";
Main.main(new String[] { "-c", "-a", command, command, command });
}

@Test
public void runThreeSampleCppAIPrograms() {
String command = "SampleAI/Cpp/a.exe";
Main.main(new String[] { "-c", "-a", command, command, command });
}

@Test
public void runThreeSampleHaskellAIPrograms() {
String command = "SampleAI/Haskell/Main.exe";
Main.main(new String[] { "-c", "-a", command, command, command });
}

@Test
public void runThreeSampleScalaAIPrograms() {
String command = isWindows() ? "scala.bat -cp SampleAI/Scala Main" : "scala -cp SampleAI/Scala Main";
Main.main(new String[] { "-c", "-a", command, command, command });
}

@Test
public void runNonExistentJavaAIPrograms() {
String command = "java -cp foo bar";
Main.main(new String[] { "-c", "-a", command, command, command });
}

@Test
public void runThreeHeavyAIPrograms() {
String command = "java -cp SampleAI/HeavyJava Main";
Main.main(new String[] { "-c", "-a", command, command, command });
}
// @Test
// public void runThreeSampleJavaAIPrograms() {
// String command = "java -cp SampleAI/Java Main";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }
//
// @Test
// public void runThreeSampleCppAIPrograms() {
// String command = "SampleAI/Cpp/a.exe";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }
//
// @Test
// public void runThreeSampleHaskellAIPrograms() {
// String command = "SampleAI/Haskell/Main.exe";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }
//
// @Test
// public void runThreeSampleScalaAIPrograms() {
// String command = isWindows() ? "scala.bat -cp SampleAI/Scala Main" : "scala -cp SampleAI/Scala Main";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }
//
// @Test
// public void runNonExistentJavaAIPrograms() {
// String command = "java -cp foo bar";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }
//
// @Test
// public void runThreeHeavyAIPrograms() {
// String command = "java -cp SampleAI/HeavyJava Main";
// Main.main(new String[] { "-c", "-a", command, command, command });
// }

private static boolean isWindows() {
return System.getProperty("os.name").contains("Windows");
Expand Down
Loading

0 comments on commit 2716b91

Please sign in to comment.