1 / 33

ICFP プログラミングコンテストに

ICFP プログラミングコンテストに. 言語で参加してみた. @ kinaba ( 稲葉 一浩 ). 自己紹介. D 言語 の言語仕様の日本語訳をしています 最近更新が遅くてすみません. 日本語訳ページの紹介. 去年から github に 翻訳レポジトリを 置きました。 1 Click で 誤訳等の 修正リクエスト できます。. 本題. ICFP とは. λ 計算. 型システム. Haskell, ML, Scheme. プログラム 検証. ICFP Programming Contest. ICFP の主催するプログラミングコンテスト

nora-franco
Download Presentation

ICFP プログラミングコンテストに

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ICFP プログラミングコンテストに 言語で参加してみた @kinaba (稲葉 一浩)

  2. 自己紹介 • D言語の言語仕様の日本語訳をしています • 最近更新が遅くてすみません

  3. 日本語訳ページの紹介 去年から githubに翻訳レポジトリを置きました。1Clickで 誤訳等の修正リクエストできます。

  4. 本題

  5. ICFP とは λ計算 型システム Haskell, ML, Scheme プログラム検証

  6. ICFP Programming Contest • ICFP の主催するプログラミングコンテスト • 6月か7月に開催 (の年が多い) • 72時間勝負 (の年が多い) • チーム人数制限なし (の年が多い) • コンテストで競うテーマは年によってさまざま • (ゲームの AI を作ることが多い)

  7. 勝つと、使った言語が表彰されます • In addition (to 賞金), the organizers will declare ... • the first place team's language is "the programming language of choice for discriminating hackers", • the second place team's language is "a fine tool for many applications“, and ... 使用言語は自由(関数型言語に限りません!)

  8. 各言語のコミュニティで話題になれます

  9. 自分の戦績 • 2003 : OCaml • 2004 : JavaScript • 2005 : JavaScript • 2006 : D, (Ruby, Java) => 2位 • 2007 : C++ • 2008 : JavaScript • 2009 : Java • 2010 : D, Ruby, (OCaml, Java) • 2011 : (出題) • 2012 : D => 6位

  10. 今年の問題

  11. 今年の問題の入出力仕様 • 標準入力でマップのデータが渡される • アスキーアート • 標準出力に文字列で操作列を出力 • [UDLRS]* • 制限時間160秒が近づくとSIGINT シグナルで知らせるので適切に終了 という動作をする、Debian 32bitで動く実行ファイルを提出すれば良い

  12. www.kmonos.net/repos/icfpc12 やったこと

  13. gui.d • 「可視化」は超重要

  14. google: icfp visualizer

  15. gui.d • DFL を使いました • http://www.dprogramming.com/dfl.php • https://github.com/Rayerd/dfl

  16. gui.dの雰囲気 this.keyDown ~= (Control c, KeyEventArgsev) { switch(ev.keyCode) {case Keys.DOWN: do_manual_command('D'); break; case Keys.UP: do_manual_command('U'); break; ... };

  17. やりたかったけどできなかったこと

  18. util.d • いつも自分がつかっているユーティリティ

  19. util.d • クラス定義に一行足すと、色々なメソッドを自動定義します • 名前は Haskell の deriving (Eq, Ord, Show) 由来 class Point { public immutable int x, y; mixinDeriveCreate; mixinDeriveCompare; mixinDeriveShow; } new Point(12, 345) (p1 == p2), p1.toHash() p.toString == “Point(x: 12, y:345)”

  20. util.dの雰囲気 template DeriveShow() { override: string toString() const{ string str= typeof(this).stringof ~ "("; foreach(i,mem; this.tupleof) { if(i) str ~= ", "; str = str~ this.tupleof[i].stringof[5..$] ~ ":" ~ text(mem); } return str ~ ")"; } }

  21. solver.d • がんばりました

  22. solver.d • 戦略 • “一番近い 「λ」 へ最短で突き進む”の繰り返し • 盤面が大きく変化しそうなルートは距離を大きくとる • 20手先読みしてGame Over ならランダムに数手動きを変える

  23. 戦略 • そんなに賢いことはやっていない •  72時間なので、他のチームもそんなに大したことはできない。当たり前のルーチンを確実に実装するだけでそこそこな順位を取れる • 実行速度が重要だった • 最大 1000 × 1000 = 1MB のマップを160秒で探索しきれないといけない

  24. (実は久しぶりにそれなりの規模のD プログラムを書いてみて)不満だったところ • constなオブジェクトを指す書き換え可能な変数が欲しい • 昔は const Type と const(Type) の区別ができた気がする・・・ const(Point2d) p = new Point2d; p.x = 100; // ERROR. GOOD!! p = new Point2d; // ERROR! WHY?

  25. 今日の準備中にきづいたこと 余談(去年の7月のコードを今のdmdでコンパイルしてみたらどうなるか)

  26. 2.059 -> 2.062 extern(C) static void catch_sigint(int) { ... } core.stdc.signal.signal(SIGINT, &catch_sigint); output.d(85): Error: function core.stdc.signal.signal( intsig, extern (C) void function(int) nothrow @system func) is not callable using argument types (int,extern (C) void function(int _param_0)) output.d(85): Error: cannot implicitly convert expression (& catch_sigint) of type extern (C) void function(int _param_0) to extern (C) void function(int) nothrow @system

  27. 2.059 -> 2.062 import std.typecons; void main() { Tuple!(int,int)[] a, b; (true ? a : b) ~= tuple(1,2); } a.d(6): Error: &a is not an lvalue a.d(6): Error: __error is not an lvalue a.d(6): Error: cannot append type Tuple!(int, int) to type Tuple!(int, int)[]* ?

  28. まとめ

  29. ICFPコンテストは • 関数型言語の会議ですが… • どんな言語で参戦しても OK! • みなさまの好きな言語 (D!) を宣伝しましょう • ゲームAIを作れというタスクが多いですが… • 短期間の戦いなので、GUI や管理Webサービスなど、人間とインタラクトできる環境が簡単に作れることが重要 • ゲームAIの知識はほとんどいらない • 高機能で高速な言語は当然有利 (D!)

  30. 今年もあるようです(多分6月か7月) • Let’s join and enjoy!!!

  31. おまけ

  32. 全自動ソートキラー http://www.kmonos.net/wlog/128.html#_2343121201 ソートアルゴリズム非依存でsort 関数の最悪ケース「を発見するアルゴリズム」

  33. std.algorithm.sort #cmp array size

More Related