東方算程譚

Oriental Code Talk ── επιστημηが与太をこく、弾幕とは無縁のシロモノ。

目次

Blog 利用状況

ニュース

著作とお薦めの品々は

著作とお薦めの品々は
東方熱帯林へ。

あわせて読みたい

わんくま

  1. 東京勉強会#2
    C++/CLI カクテル・レシピ
  2. 東京勉強会#3
    template vs. generics
  3. 大阪勉強会#6
    C++むかしばなし
  4. 東京勉強会#7
    C++むかしばなし
  5. 東京勉強会#8
    STL/CLRによるGeneric Programming
  6. TechEd 2007 @YOKOHAMA
    C++・C++/CLI・C# 適材適所
  7. 東京勉強会#14
    Making of BOF
  8. 東京勉強会#15
    状態遷移
  9. 名古屋勉強会#2
    WinUnit - お気楽お手軽UnitTest

CodeZine

  1. Cで実現する「ぷちオブジェクト指向」
  2. CUnitによるテスト駆動開発
  3. SQLiteで組み込みDB体験(2007年版)
  4. C++/CLIによるCライブラリの.NET化
  5. C# 1.1からC# 3.0まで~言語仕様の進化
  6. BoostでC++0xのライブラリ「TR1」を先取りしよう (1)
  7. BoostでC++0xのライブラリ「TR1」を先取りしよう (2)
  8. BoostでC++0xのライブラリ「TR1」を先取りしよう (3)
  9. BoostでC++0xのライブラリ「TR1」を先取りしよう (4)
  10. BoostでC++0xのライブラリ「TR1」を先取りしよう (5)
  11. C/C++に対応した、もうひとつのUnitTestFramework ─ WinUnit
  12. SQLiteで"おこづかいちょう"
  13. STL/CLRツアーガイド
  14. マージ・ソート : 巨大データのソート法
  15. ヒープソートのアルゴリズム
  16. C++0xの新機能「ラムダ式」を次期Visual Studioでいち早く試す
  17. .NETでマンデルブロ集合を描く
  18. .NETでマンデルブロ集合を描く(後日談)
  19. C++/CLI : とある文字列の相互変換(コンバージョン)
  20. インテルTBBによる選択ソートの高速化
  21. インテルTBB3.0 によるパイプライン処理
  22. Visual C++ 2010に追加されたSTLアルゴリズム
  23. Visual C++ 2010に追加されたSTLコンテナ「forward_list」
  24. shared_ptrによるObserverパターンの実装
  25. .NETでマンデルブロ集合を描く(番外編) ── OpenCLで超並列コンピューティング
  26. StateパターンでCSVを読む
  27. 状態遷移表からStateパターンを自動生成する
  28. 「ソートも、サーチも、あるんだよ」~標準C++ライブラリにみるアルゴリズムの面白さ
  29. インテルTBBの同期メカニズム
  30. なぜsetを使っちゃいけないの?
  31. WPFアプリケーションで腕試し ~C++でもWPFアプリを
  32. C++11 : スレッド・ライブラリひとめぐり
  33. Google製のC++ Unit Test Framework「Google Test」を使ってみる
  34. メールでデータベースを更新するココロミ
  35. Visitorパターンで遊んでみたよ
  36. Collection 2題:「WPFにバインドできる辞書」と「重複を許す検索set」
  37. Visual C++ 2012:stateless-lambdaとSQLiteのぷち拡張
  38. 「Visual C++ Compiler November 2012 CTP」で追加された6つの新機能

@IT

  1. Vista時代のVisual C++の流儀(前編)Vista到来。既存C/C++資産の.NET化を始めよう!
  2. Vista時代のVisual C++の流儀(中編)MFCから.NETへの実践的移行計画
  3. Vista時代のVisual C++の流儀(後編) STL/CLRによるDocument/Viewアーキテクチャ
  4. C++開発者のための単体テスト入門 第1回 C++開発者の皆さん。テスト、ちゃんとしていますか?
  5. C++開発者のための単体テスト入門 第2回 C++アプリケーションの効率的なテスト手法(CppUnit編)
  6. C++開発者のための単体テスト入門 第3回 C++アプリケーションの効率的なテスト手法(NUnit編)

AWARDS


Microsoft MVP
for Visual Developer - Visual C++


Wankuma MVP
for いぢわる C++


Nyantora MVP
for こくまろ中国茶

Xbox

Links

記事カテゴリ

書庫

日記カテゴリ

申し訳なし

一向に鎮火しません。 → C#で、、、
原因の一端は僕にあります。ごめんなさい。 _o/L

正常ルートに戻りそうもないし、スレ主も逃げ出したみたいだから:

using System;
using System.Collections.Generic;
using System.Drawing;

namespace Othello {

    enum Piece { none, Black, White };

    class Board {
      private Piece[,] board_;
      private readonly int N = 8;

      // コンストラクタ
      public Board() { board_ = new Piece[N,N];
        for ( int x = 0; x < N; ++x ) {
          for ( int y = 0; y < N; ++y ) {
            board_[x,y] = Piece.none;
          }
        }
        board_[2,2] = Piece.Black;
        board_[3,3] = Piece.Black;
        board_[2,3] = Piece.White;
        board_[3,2] = Piece.White;
      }

      // (x,y)はボードの上か?
      private bool onBoard(int x, int y) {
        if ( x < 0 || x >= N ) return false;
        if ( y < 0 || y >= N ) return false;
        return true;
      }

      // (x,y)に色pの駒を置いたとき(dx,dy)方向に何枚反転できるか?
      // dx, dy : -1/0/1 のいずれか
      private int flippablePieces(Piece p,
               int x, int y, int dx, int dy) {
        // (x,y)に駒があったらダメ
        if ( board_[x,y] != Piece.none ) return 0;
        int result = 0;
        // x,yのそれぞれをdx,dyだけ変化させ、
        // そこがボード上であり空マスでない間
        while ( onBoard(x+=dx,y+=dy) &&
         board_[x,y] != Piece.none ) {
          // 置いた駒と同色ならそこまでの反転数を返す
          if ( board_[x,y] == p ) { return result; }
          // 置いた駒と異なるなら、反転数+1
          else { ++result; }
        }
        return 0;
      }

      // (x,y)に色pの駒を置いたとき何枚反転できるか?
      public int flippablePieces(Piece p, int x, int y) {
        int result = 0;
        // 8方向について調べ、結果を積算
        for ( int dx = -1; dx <= 1; ++dx ) {
          for ( int dy = -1; dy <= 1; ++dy ) {
            result += flippablePieces(p,x,y,dx,dy);
          }
        }
        return result;
      }

      // (x,y)に置かれたpが(dx,dy)方向の敵コマを反転する
      private int putPiece(Piece p,
             int x, int y, int dx, int dy ) {
        List<Point> flips = new List<Point>();
        flips.Add(new Point(x,y));
        while ( onBoard(x+=dx,y+=dy) &&
         board_[x,y] != Piece.none ) {
          if ( board_[x,y] == p ) { break; }
          else { flips.Add(new Point(x,y)); }
        }
        if ( board_[x,y] == p ) {
          foreach ( Point pt in flips ) board_[pt.X,pt.Y] = p;
        }     
        return flips.Count-1;
      }

      // (x,y)に置かれたpが8方向の敵コマを反転する
      public int putPiece(Piece p, int x, int y) {
        int result = 0;
        for ( int dx = -1; dx <= 1; ++dx ) {
          for ( int dy = -1; dy <= 1; ++dy ) {
            result += putPiece(p,x,y,dx,dy);
          }
        }
        return result;
      }

      // ボード上のpと同色の駒を数える
      public int countPieces(Piece p) {
        int result = 0;
        foreach ( Piece item in board_ ) {
          if ( item == p ) ++result;
        }
        return result;
      }

      public void dump() {
        for ( int x = 0; x < N; ++x ) {
          for ( int y = 0; y< N; ++y ) {
            switch ( board_[x,y] ) {
            case Piece.none:  Console.Write(" "); break;
            case Piece.Black: Console.Write("●"); break;
            case Piece.White: Console.Write("○"); break;
            }
          }
          Console.WriteLine();
        }
      }
    }

}

投稿日時 : 2008年5月16日 11:29

コメントを追加

# re: 申し訳なし 2008/05/16 12:17 ゆーち

後輩の方々が、こんなふうに、ちゃちゃっと書けちゃうように、そうなれるように・・・。

100点満点の完成コメントは不可能ではないかと思うので、60点以上のコメントでサポートしていきましょうよ。

なんも悪くないので、謝らなくていいとおもうです。

賛否両論って当然ですから、とらえかたにいろいろあるのだという意識を持ってりゃOK。(^-^)v

# re: 申し訳なし 2008/05/16 12:31 774RR

[2,2]っすか?ちょっとずれている気のせいがする

# re: 申し訳なし 2008/05/16 12:38 επιστημη

あらホント、ズレてる。

# re: 申し訳なし 2008/05/16 13:00 みゃま

通りすがりですみません。サンプルコード拝領します。

昔、「だれそれのゲームプログラミング」とか「ベーマガ」といった書籍で、遊びたいゲームを選んで全部打ち込んでデバッグして、という作業が、敷居は低くかつ結構勉強になった記憶がよみがえりました。

もちろんそこまで付き合ってあげる義理は無いんですが(^^;

同類の本を探してみたのですがパッと見つからないのは探し方が悪いでしょうか。

# re: 申し訳なし 2008/05/16 13:08 επιστημη

コードと真っ正面から向き合う本は少なくなりましたねー
DVDがオマケについちゃうからご時勢じゃ
紙面にリスト載せんでもいいからねー

# コーンフレーク買ったらフィットネスの
# チュートリアルDVDがおマケに付いてきた。

# re: 申し訳なし 2008/05/16 13:15 はつね

> 遊びたいゲームを選んで全部打ち込んでデバッグ

この「全部打ち込んで」という部分が重要なんじゃなかろうかと思っています。コピペじゃだめなんですよね。自分で最低でも手を動かさないと。
いまだとインテリセンス付いているので各メンバのみるきっかけにもなるだろうし。

> επιστημηさん
このコードを最初にどんと提示されたとしたら、すぐに理解できなかった。やっぱ、日本語でOKな世界で考え方が示されていないとコピペで動いたら終わりとなりそう>自分の場合

# re: 申し訳なし 2008/05/16 13:33 επιστημη

> 最初にどんと提示されたとしたら

なのよね。
「書く訓練を積まないと読めるようにはならない」し。

# re: 申し訳なし 2008/05/16 13:59 いしだ

foreachって多次元でもいけたのか。
知らなかった。。。

オセロは、十数年前に約1ヶ月のC言語教育の最終課題として、3日かけて作った覚えがあります。
もちろん、こんなにエレガントには書けませんでしたが(今でもそうか。。。)。

# C#でリバーシ 2008/05/16 14:30 菊池 Blog

C#でリバーシ

# re: 申し訳なし 2008/05/16 14:30 とっちゃん

これを画像で張れれば。。。手作業で打ち込みになるので
多少は訓練になるんですけどねw

テキストデータだと、Ctrl+C, Ctrl+V で終わっちゃうからなぁ...w

でも、おいらもこれをいきなり見たら...コピーペーストで終わりそうw

# re: 申し訳なし 2008/05/16 23:39 επιστημη

僕のblogを読んでくれてる方々が気を悪く
しそうだから消します。
痕跡を残さないのはフェアじゃないから
ログはこちら↓
http://cid-07c558f8e11e708f.skydrive.live.com/self.aspx/%e5%85%ac%e9%96%8b/%e5%88%9d%e3%82%ab%e3%82%ad%e3%82%b3.txt

あなたの留飲も下がっただろうし、僕と対話するのが
目的ならメールください。

# 優しいのは 2008/05/17 14:02 何となく Blog by Jitta

優しいのは

# re: 申し訳なし 2008/05/17 22:01 倉田 有大

えー、お疲れ様としか言いようがないなー

# re: 申し訳なし 2008/05/29 14:32 PATIO

ここまで紛糾してたんですねぇ。

ログの方は読んできましたけど。
私的には御本人の気持ちは理解できないなあと
そんな所です。

いろんな意味で御両人ともお疲れ様でした。

# Hey there! This is kind of off topic but I need some guidance from an established blog. Is it very difficult to set up your own blog? I'm not very techincal but I can figure things out pretty quick. I'm thinking about making my own but I'm not sure where 2021/08/30 2:36 Hey there! This is kind of off topic but I need s

Hey there! This is kind of off topic but I need some guidance from an established blog.
Is it very difficult to set up your own blog? I'm not
very techincal but I can figure things out pretty quick.

I'm thinking about making my own but I'm not sure where to start.

Do you have any points or suggestions? Cheers

# I like the valuable info you provide in your articles. I'll bookmark your weblog and check again here frequently. I'm quite certain I'll learn many new stuff right here! Best of luck for the next! 2021/09/01 4:25 I like the valuable info you provide in your artic

I like the valuable info you provide in your articles.
I'll bookmark your weblog and check again here frequently.
I'm quite certain I'll learn many new stuff right here!
Best of luck for the next!

# I like the valuable info you provide in your articles. I'll bookmark your weblog and check again here frequently. I'm quite certain I'll learn many new stuff right here! Best of luck for the next! 2021/09/01 4:26 I like the valuable info you provide in your artic

I like the valuable info you provide in your articles.
I'll bookmark your weblog and check again here frequently.
I'm quite certain I'll learn many new stuff right here!
Best of luck for the next!

# I like the valuable info you provide in your articles. I'll bookmark your weblog and check again here frequently. I'm quite certain I'll learn many new stuff right here! Best of luck for the next! 2021/09/01 4:27 I like the valuable info you provide in your artic

I like the valuable info you provide in your articles.
I'll bookmark your weblog and check again here frequently.
I'm quite certain I'll learn many new stuff right here!
Best of luck for the next!

# I like the valuable info you provide in your articles. I'll bookmark your weblog and check again here frequently. I'm quite certain I'll learn many new stuff right here! Best of luck for the next! 2021/09/01 4:28 I like the valuable info you provide in your artic

I like the valuable info you provide in your articles.
I'll bookmark your weblog and check again here frequently.
I'm quite certain I'll learn many new stuff right here!
Best of luck for the next!

# Hurrah! At last I got a web site from where I be able to actually obtain helpful facts regarding my study and knowledge. 2021/09/03 8:50 Hurrah! At last I got a web site from where I be a

Hurrah! At last I got a web site from where I be able to actually obtain helpful facts regarding my study and knowledge.

# Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb usability and visual appearance. I must say you have done a fantastic job w 2021/09/04 9:44 Woah! I'm really enjoying the template/theme of t

Woah! I'm really enjoying the template/theme of this site.
It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb
usability and visual appearance. I must say you have done a fantastic job with this.
In addition, the blog loads super fast for me on Safari. Excellent
Blog!

# Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb usability and visual appearance. I must say you have done a fantastic job w 2021/09/04 9:45 Woah! I'm really enjoying the template/theme of t

Woah! I'm really enjoying the template/theme of this site.
It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb
usability and visual appearance. I must say you have done a fantastic job with this.
In addition, the blog loads super fast for me on Safari. Excellent
Blog!

# Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb usability and visual appearance. I must say you have done a fantastic job w 2021/09/04 9:46 Woah! I'm really enjoying the template/theme of t

Woah! I'm really enjoying the template/theme of this site.
It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb
usability and visual appearance. I must say you have done a fantastic job with this.
In addition, the blog loads super fast for me on Safari. Excellent
Blog!

# Woah! I'm really enjoying the template/theme of this site. It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb usability and visual appearance. I must say you have done a fantastic job w 2021/09/04 9:47 Woah! I'm really enjoying the template/theme of t

Woah! I'm really enjoying the template/theme of this site.
It's simple, yet effective. A lot of times it's very difficult to get that "perfect balance" between superb
usability and visual appearance. I must say you have done a fantastic job with this.
In addition, the blog loads super fast for me on Safari. Excellent
Blog!

# I'm gone to tell my little brother, that he should also pay a visit this website on regular basis to obtain updated from latest news. quest bars http://j.mp/3C2tkMR quest bars 2021/09/11 11:46 I'm gone to tell my little brother, that he should

I'm gone to tell my little brother, that he should also pay a visit this website on regular basis to obtain updated from latest
news. quest bars http://j.mp/3C2tkMR quest bars

# It's very simple to find out any topic on web as compared to books, as I found this post at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 7:18 It's very simple to find out any topic on web as c

It's very simple to find out any topic on web as compared to books, as I found this post
at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# It's very simple to find out any topic on web as compared to books, as I found this post at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 7:19 It's very simple to find out any topic on web as c

It's very simple to find out any topic on web as compared to books, as I found this post
at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# It's very simple to find out any topic on web as compared to books, as I found this post at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 7:20 It's very simple to find out any topic on web as c

It's very simple to find out any topic on web as compared to books, as I found this post
at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# It's very simple to find out any topic on web as compared to books, as I found this post at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars 2021/09/14 7:21 It's very simple to find out any topic on web as c

It's very simple to find out any topic on web as compared to books, as I found this post
at this web site. quest bars https://www.iherb.com/search?kw=quest%20bars quest bars

# Hi, after reading this remarkable post i am also happy to share my know-how here with mates. 2021/10/26 0:11 Hi, after reading this remarkable post i am also h

Hi, after reading this remarkable post i am also happy to share my know-how here with mates.

# I'm not sure exactly why but this web site is loading extremely slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back later and see if the problem still exists. 2021/12/07 8:39 I'm not sure exactly why but this web site is load

I'm not sure exactly why but this web site is loading extremely slow for me.

Is anyone else having this problem or is it a problem on my end?
I'll check back later and see if the problem still exists.

# I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web. 2021/12/25 9:58 I every time used to study post in news papers but

I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web.

# I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web. 2021/12/25 9:59 I every time used to study post in news papers but

I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web.

# I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web. 2021/12/25 9:59 I every time used to study post in news papers but

I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web.

# I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web. 2021/12/25 10:00 I every time used to study post in news papers but

I every time used to study post in news papers but now as I am a user of internet so from now I am using net for content, thanks to web.

# PPwbMyVtOKksrFp 2022/04/19 10:34 johnansaz

http://imrdsoacha.gov.co/silvitra-120mg-qrms

# When I initally commeented I cclicked the "Notify me when new comments are added" checobox and now eachh time a comment is added I get four e-mails withh thee sane comment. Is tere any wway yoou caan remove me from tht service? Thanks! 2022/11/22 4:33 When I inktially commented I cliucked thee "

When I initially commented I clicxked the "Notify me when new comments are added" checkbox and now eachh tie a comment iis added I get ffour e-mails with thhe sam comment.
Is there aany way you caan remove me from thawt service?
Thanks!

# Hi thhere i aam kavin, its mmy first time to commenting anywhere, whedn i read this post i thught i coupd also make commen due too this giod post. 2023/03/03 19:09 Hi there i am kavin, its my first time to ccomment

Hi there i amm kavin, its my first time to
commentting anywhere, whhen i read this post i thought i could also make comment due to thiis goood post.

# Hi thhere i aam kavin, its mmy first time to commenting anywhere, whedn i read this post i thught i coupd also make commen due too this giod post. 2023/03/03 19:09 Hi there i am kavin, its my first time to ccomment

Hi there i amm kavin, its my first time to
commentting anywhere, whhen i read this post i thought i could also make comment due to thiis goood post.

# Hi thhere i aam kavin, its mmy first time to commenting anywhere, whedn i read this post i thught i coupd also make commen due too this giod post. 2023/03/03 19:10 Hi there i am kavin, its my first time to ccomment

Hi there i amm kavin, its my first time to
commentting anywhere, whhen i read this post i thought i could also make comment due to thiis goood post.

# Hi thhere i aam kavin, its mmy first time to commenting anywhere, whedn i read this post i thught i coupd also make commen due too this giod post. 2023/03/03 19:11 Hi there i am kavin, its my first time to ccomment

Hi there i amm kavin, its my first time to
commentting anywhere, whhen i read this post i thought i could also make comment due to thiis goood post.

# Thiis iss a very good tip particularly to those nnew to thhe blogosphere.Short but very precise info… Thanks forr saring this one. A mjst read post! 2023/03/07 18:55 Thiss is a very ggood tip particularly too thos ne

Thiis iss a vsry good tip particlarly to hose new too thhe
blogosphere. Short buut very precisse info… Thznks for sharng thiks one.
A must read post!

# Thiis iss a very good tip particularly to those nnew to thhe blogosphere.Short but very precise info… Thanks forr saring this one. A mjst read post! 2023/03/07 18:56 Thiss is a very ggood tip particularly too thos ne

Thiis iss a vsry good tip particlarly to hose new too thhe
blogosphere. Short buut very precisse info… Thznks for sharng thiks one.
A must read post!

# Thiis iss a very good tip particularly to those nnew to thhe blogosphere.Short but very precise info… Thanks forr saring this one. A mjst read post! 2023/03/07 18:57 Thiss is a very ggood tip particularly too thos ne

Thiis iss a vsry good tip particlarly to hose new too thhe
blogosphere. Short buut very precisse info… Thznks for sharng thiks one.
A must read post!

# Thiis iss a very good tip particularly to those nnew to thhe blogosphere.Short but very precise info… Thanks forr saring this one. A mjst read post! 2023/03/07 18:58 Thiss is a very ggood tip particularly too thos ne

Thiis iss a vsry good tip particlarly to hose new too thhe
blogosphere. Short buut very precisse info… Thznks for sharng thiks one.
A must read post!

# lana rhoades video - https://lanarhoades.fun/ lana rhodes
2024/03/02 21:23 Rhodess

lana rhoades video - https://lanarhoades.fun/ lana rhodes

# eva elfie full videos https://evaelfie.site/ eva elfie new video
2024/03/07 2:09 EvaElfie

eva elfie full videos https://evaelfie.site/ eva elfie new video

# como jogar aviator https://aviatormocambique.site aviator mo&#231;ambique
2024/03/11 20:52 AviatorMaz

como jogar aviator https://aviatormocambique.site aviator mo&#231;ambique

# estrela bet aviator https://aviatorjogar.online/ - aviator jogo
2024/03/12 17:30 BraAvia

estrela bet aviator https://aviatorjogar.online/ - aviator jogo

# g&#252;ncel sweet bonanza https://sweetbonanza.bid/ - sweet bonanza slot demo
2024/03/27 19:38 Bonanzaj

g&#252;ncel sweet bonanza https://sweetbonanza.bid/ - sweet bonanza slot demo

タイトル  
名前  
URL
コメント