ReversiForm  1.0.0
ReversiForm
ReversiPlay.cs
Go to the documentation of this file.
1 
18 using System;
19 using System.Collections.Generic;
20 using System.Linq;
21 using System.Text;
22 
23 namespace ReversiForm
24 {
30  public class ReversiPlay
31  {
32  #region デリゲート
33  public delegate void ViewMsgDlg(string title , string msg);
34  public delegate void DrawSingle(int y, int x, int sts, int bk, string text);
35  public delegate void CurColMsg(string text);
36  public delegate void CurStsMsg(string text);
37  #endregion
38 
39  #region メンバ変数
40  private MyReversi _mReversi;
42  private int _mCurColor = 0;
43  private ReversiPoint[] _mCpu;
44  private ReversiPoint[] _mEdge;
45  private int _mPassEnaB = 0;
46  private int _mPassEnaW = 0;
47  private int _mGameEndSts = 0;
48  private int _mPlayLock = 0;
49  private ViewMsgDlg _viewMsgDlg = null;
50  private DrawSingle _drawSingle = null;
51  private CurColMsg _curColMsg = null;
52  private CurStsMsg _curStsMsg = null;
53  private System.Random r = new System.Random();
54  #endregion
55 
56  #region プロパティ
57  public MyReversi mReversi
58  {
59  get { return _mReversi; }
60  set { _mReversi = value; }
61  }
62  public ReversiSetting mSetting
63  {
64  get { return _mSetting; }
65  set { _mSetting = value; }
66  }
67  public int mCurColor
68  {
69  get { return _mCurColor; }
70  set { _mCurColor = value; }
71  }
72  public ReversiPoint[] mCpu
73  {
74  get { return _mCpu; }
75  set { _mCpu = value; }
76  }
77  public ReversiPoint[] mEdge
78  {
79  get { return _mEdge; }
80  set { _mEdge = value; }
81  }
82  public int mPassEnaB
83  {
84  get { return _mPassEnaB; }
85  set { _mPassEnaB = value; }
86  }
87  public int mPassEnaW
88  {
89  get { return _mPassEnaW; }
90  set { _mPassEnaW = value; }
91  }
92  public int mGameEndSts
93  {
94  get { return _mGameEndSts; }
95  set { _mGameEndSts = value; }
96  }
97  public int mPlayLock
98  {
99  get { return _mPlayLock; }
100  set { _mPlayLock = value; }
101  }
102  public ViewMsgDlg viewMsgDlg
103  {
104  get { return _viewMsgDlg; }
105  set { _viewMsgDlg = value; }
106  }
107  public DrawSingle drawSingle
108  {
109  get { return _drawSingle; }
110  set { _drawSingle = value; }
111  }
112  public CurColMsg curColMsg
113  {
114  get { return _curColMsg; }
115  set { _curColMsg = value; }
116  }
117  public CurStsMsg curStsMsg
118  {
119  get { return _curStsMsg; }
120  set { _curStsMsg = value; }
121  }
122  #endregion
123 
132  public ReversiPlay()
133  {
135  this.mSetting = new ReversiSetting();
139  this.mCpu[i] = new ReversiPoint();
140  this.mEdge[i] = new ReversiPoint();
141  }
142  }
143 
153  {
154  return (ReversiPlay)MemberwiseClone();
155  }
156 
167  public void reversiPlay(int y, int x)
168  {
169  int update = 0;
170  int cpuEna = 0;
171  int tmpCol = this.mCurColor;
172  int pass = 0;
173 
174  if(this.mPlayLock == 1) return;
175  this.mPlayLock = 1;
176  if (this.mReversi.getColorEna(this.mCurColor) == 0) {
177  if (this.mReversi.setMasuSts(this.mCurColor, y, x) == 0) {
178  if (this.mSetting.mType == ReversiConst.DEF_TYPE_HARD) this.mReversi.AnalysisReversi(this.mPassEnaB, this.mPassEnaW);
179  if (this.mSetting.mAssist == ReversiConst.DEF_ASSIST_ON) {
180  // *** メッセージ送信 *** //
182  }
183  this.sendDrawMsg(y, x); // 描画
184  this.drawUpdate(ReversiConst.DEF_ASSIST_OFF); // その他コマ描画
185  if (this.mReversi.getGameEndSts() == 0) {
187  else tmpCol = ReversiConst.REVERSI_STS_BLACK;
188  if (this.mReversi.getColorEna(tmpCol) == 0) {
189  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) { // CPU対戦
190  cpuEna = 1;
191  } else { // 二人対戦
192  this.mCurColor = tmpCol;
193  this.drawUpdate(this.mSetting.mAssist); // 次のプレイヤーコマ描画
194  }
195  } else {
196  // *** パスメッセージ *** //
197  this.reversiPlayPass(tmpCol);
198  pass = 1;
199  }
200  } else {
201  // *** ゲーム終了メッセージ *** //
202  this.reversiPlayEnd();
203  }
204  update = 1;
205  } else {
206  // *** エラーメッセージ *** //
207  this.ViewMsgDlgLocal("エラー", "そのマスには置けません。");
208  }
209  } else {
210  if (this.mReversi.getGameEndSts() == 0) {
212  else tmpCol = ReversiConst.REVERSI_STS_BLACK;
213  if (this.mReversi.getColorEna(tmpCol) == 0) {
214  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) { // CPU対戦
215  update = 1;
216  cpuEna = 1;
217  } else { // 二人対戦
218  this.mCurColor = tmpCol;
219  }
220  } else {
221  // *** パスメッセージ *** //
222  this.reversiPlayPass(tmpCol);
223  pass = 1;
224  }
225  } else {
226  // *** ゲーム終了メッセージ *** //
227  this.reversiPlayEnd();
228  }
229  }
230  if (pass == 1) {
231  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) { // CPU対戦
232  if (this.mSetting.mAssist == ReversiConst.DEF_ASSIST_ON) {
233  // *** メッセージ送信 *** //
235  }
236  }
237  }
238  if (update == 1) {
239  var waitTime = 0;
240  if (cpuEna == 1) {
241  waitTime = this.mSetting.mPlayCpuInterVal;
242  }
243  System.Threading.Thread.Sleep(waitTime);
244  this.reversiPlaySub(cpuEna, tmpCol);
245  this.mPlayLock = 0;
246  }else{
247  this.mPlayLock = 0;
248  }
249  }
250 
261  public void reversiPlaySub(int cpuEna, int tmpCol)
262  {
263  int ret;
264  for (; ;) {
265  ret = this.reversiPlayCpu(tmpCol, cpuEna);
266  cpuEna = 0;
267  if (ret == 1) {
268  if (this.mReversi.getGameEndSts() == 0) {
269  if (this.mReversi.getColorEna(this.mCurColor) != 0) {
270  // *** パスメッセージ *** //
271  this.reversiPlayPass(this.mCurColor);
272  cpuEna = 1;
273  }
274  } else {
275  // *** ゲーム終了メッセージ *** //
276  this.reversiPlayEnd();
277  }
278  }
279  if (cpuEna == 0) break;
280  }
281  }
282 
291  public void reversiPlayEnd()
292  {
293  if (this.mGameEndSts == 0) {
294  this.mGameEndSts = 1;
295  var waitTime = this.gameEndAnimExec(); // 終了アニメ実行
296  this.mPlayLock = 1;
297  System.Threading.Thread.Sleep(waitTime);
298  // *** ゲーム終了メッセージ *** //
299  string tmpMsg1, tmpMsg2, msgStr;
300  int blk, whi;
301  blk = this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_BLACK);
302  whi = this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_WHITE);
303  tmpMsg1 = "プレイヤー1 = " + blk.ToString() + " プレイヤー2 = " + whi.ToString();
304  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) {
305  if (whi == blk) tmpMsg2 = "引き分けです。";
306  else if (whi < blk) {
307  if (this.mCurColor == ReversiConst.REVERSI_STS_BLACK) tmpMsg2 = "あなたの勝ちです。";
308  else tmpMsg2 = "あなたの負けです。";
309  } else {
310  if (this.mCurColor == ReversiConst.REVERSI_STS_WHITE) tmpMsg2 = "あなたの勝ちです。";
311  else tmpMsg2 = "あなたの負けです。";
312  }
313  } else {
314  if (whi == blk) tmpMsg2 = "引き分けです。";
315  else if (whi < blk) tmpMsg2 = "プレイヤー1の勝ちです。";
316  else tmpMsg2 = "プレイヤー2の勝ちです。";
317  }
318  msgStr = tmpMsg1 + tmpMsg2;
319  this.ViewMsgDlgLocal("ゲーム終了", msgStr);
320 
321  if (this.mSetting.mEndAnim == ReversiConst.DEF_END_ANIM_ON) {
322  // *** メッセージ送信 *** //
324  // *** メッセージ送信 *** //
326  }
327  }
328  }
329 
339  public void reversiPlayPass(int color)
340  {
341  // *** パスメッセージ *** //
342  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) {
343  if (color == this.mCurColor) this.ViewMsgDlgLocal("", "あなたはパスです。");
344  else this.ViewMsgDlgLocal("", "CPUはパスです。");
345  } else {
346  if (color == ReversiConst.REVERSI_STS_BLACK) this.ViewMsgDlgLocal("", "プレイヤー1はパスです。");
347  else this.ViewMsgDlgLocal("", "プレイヤー2はパスです。");
348  }
349  }
350 
361  public int reversiPlayCpu(int color, int cpuEna)
362  {
363  int update = 0;
364  int setY;
365  int setX;
366 
367  for (; ;) {
368  if (cpuEna == 1) {
369  cpuEna = 0;
370  // *** CPU対戦 *** //
371  int pCnt = this.mReversi.getPointCnt(color);
372  ReversiPoint pInfo = this.mReversi.getPoint(color, r.Next(pCnt));
373  if (pInfo != null) {
374  setY = pInfo.y;
375  setX = pInfo.x;
376  if (this.mSetting.mType != ReversiConst.DEF_TYPE_EASY) { // 強いコンピューター
377  int cpuflg0, cpuflg1, cpuflg2, cpuflg3, mem, mem2, mem3, mem4, rcnt1, rcnt2, kadocnt, loop, pcnt, passCnt, othColor, othBet, ownBet, endZone;
378  cpuflg0 = 0;
379  cpuflg1 = 0;
380  cpuflg2 = 0;
381  cpuflg3 = 0;
382  mem = -1;
383  mem2 = -1;
384  mem3 = -1;
385  mem4 = -1;
386  rcnt1 = 0;
387  rcnt2 = 0;
388  kadocnt = 0;
389  loop = this.mSetting.mMasuCnt * this.mSetting.mMasuCnt;
390  pcnt = 0;
391  passCnt = 0;
393  else othColor = ReversiConst.REVERSI_STS_BLACK;
394  othBet = this.mReversi.getBetCnt(othColor); // 対戦相手のコマ数
395  ownBet = this.mReversi.getBetCnt(color); // 自分のコマ数
396  endZone = 0;
397  if ((loop - (othBet + ownBet)) <= 16) endZone = 1; // ゲーム終盤フラグON
398  for (var i = 0; i < loop; i++) {
399  this.mCpu[i].x = 0;
400  this.mCpu[i].y = 0;
401  this.mEdge[i].x = 0;
402  this.mEdge[i].y = 0;
403  }
404 
405  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
406  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
407  if (this.mReversi.getMasuStsEna(color, i, j) != 0) {
408  // *** 角の一つ手前なら別のとこに格納 *** //
409  if (this.mReversi.getEdgeSideOne(i, j) == 0) {
410  this.mEdge[kadocnt].x = j;
411  this.mEdge[kadocnt].y = i;
412  kadocnt++;
413  } else {
414  this.mCpu[rcnt1].x = j;
415  this.mCpu[rcnt1].y = i;
416  rcnt1++;
417  }
418  if (this.mSetting.mType == ReversiConst.DEF_TYPE_NOR) {
419  // *** 角に置けるなら優先的にとらせるため場所を記憶させる *** //
420  if (this.mReversi.getEdgeSideZero(i, j) == 0) {
421  cpuflg1 = 1;
422  rcnt2 = (rcnt1 - 1);
423  }
424  // *** 角の二つ手前も優先的にとらせるため場所を記憶させる *** //
425  if (cpuflg1 == 0) {
426  if (this.mReversi.getEdgeSideTwo(i, j) == 0) {
427  cpuflg2 = 1;
428  rcnt2 = (rcnt1 - 1);
429  }
430  }
431  // *** 角の三つ手前も優先的にとらせるため場所を記憶させる *** //
432  if (cpuflg1 == 0 && cpuflg2 == 0) {
433  if (this.mReversi.getEdgeSideThree(i, j) == 0) {
434  cpuflg0 = 1;
435  rcnt2 = (rcnt1 - 1);
436  }
437  }
438  }
439  // *** パーフェクトゲームなら *** //
440  if (this.mReversi.getMasuStsCnt(color, i, j) == othBet) {
441  setY = i;
442  setX = j;
443  pcnt = 1;
444  }
445  // *** 相手をパスさせるなら *** //
446  if (pcnt == 0) {
447  if (this.mReversi.getPassEna(color, i, j) != 0) {
448  setY = i;
449  setX = j;
450  passCnt = 1;
451  }
452  }
453  }
454  }
455  }
456 
457  if (pcnt == 0 && passCnt == 0) {
458  var badPoint = -1;
459  var goodPoint = -1;
460  var pointCnt = -1;
461  var ownPointCnt = -1;
462  ReversiAnz tmpAnz;
463  if (rcnt1 != 0) {
464  for (var i = 0; i < rcnt1; i++) {
465  if (this.mSetting.mType == ReversiConst.DEF_TYPE_HARD) {
466  tmpAnz = this.mReversi.getPointAnz(color, this.mCpu[i].y, this.mCpu[i].x);
467  if (tmpAnz != null) {
468  if (badPoint == -1) {
469  badPoint = tmpAnz.badPoint;
470  goodPoint = tmpAnz.goodPoint;
471  pointCnt = tmpAnz.pointCnt;
472  ownPointCnt = tmpAnz.ownPointCnt;
473  mem2 = i;
474  mem3 = i;
475  mem4 = i;
476  } else {
477  if (tmpAnz.badPoint < badPoint) {
478  badPoint = tmpAnz.badPoint;
479  mem2 = i;
480  }
481  if (goodPoint < tmpAnz.goodPoint) {
482  goodPoint = tmpAnz.goodPoint;
483  mem3 = i;
484  }
485  if (tmpAnz.pointCnt < pointCnt) {
486  pointCnt = tmpAnz.pointCnt;
487  ownPointCnt = tmpAnz.ownPointCnt;
488  mem4 = i;
489  } else if (tmpAnz.pointCnt == pointCnt) {
490  if (ownPointCnt < tmpAnz.ownPointCnt) {
491  ownPointCnt = tmpAnz.ownPointCnt;
492  mem4 = i;
493  }
494  }
495  }
496  }
497  }
498  if (this.mReversi.getMasuStsEna(color, this.mCpu[i].y, this.mCpu[i].x) == 2) {
499  mem = i;
500  }
501  }
502  if (mem2 != -1) {
503  if (endZone != 0) { // 終盤なら枚数重視
504  if (mem3 != -1) {
505  mem2 = mem3;
506  }
507  } else {
508  if (mem4 != -1) {
509  mem2 = mem4;
510  }
511  }
512  mem = mem2;
513  }
514  if (mem == -1) mem = r.Next(rcnt1);
515  } else if (kadocnt != 0) {
516  for (var i = 0; i < kadocnt; i++) {
517  if (this.mSetting.mType == ReversiConst.DEF_TYPE_HARD) {
518  tmpAnz = this.mReversi.getPointAnz(color, this.mEdge[i].y, this.mEdge[i].x);
519  if (tmpAnz != null) {
520  if (badPoint == -1) {
521  badPoint = tmpAnz.badPoint;
522  goodPoint = tmpAnz.goodPoint;
523  pointCnt = tmpAnz.pointCnt;
524  ownPointCnt = tmpAnz.ownPointCnt;
525  mem2 = i;
526  mem3 = i;
527  mem4 = i;
528  } else {
529  if (tmpAnz.badPoint < badPoint) {
530  badPoint = tmpAnz.badPoint;
531  mem2 = i;
532  }
533  if (goodPoint < tmpAnz.goodPoint) {
534  goodPoint = tmpAnz.goodPoint;
535  mem3 = i;
536  }
537  if (tmpAnz.pointCnt < pointCnt) {
538  pointCnt = tmpAnz.pointCnt;
539  ownPointCnt = tmpAnz.ownPointCnt;
540  mem4 = i;
541  } else if (tmpAnz.pointCnt == pointCnt) {
542  if (ownPointCnt < tmpAnz.ownPointCnt) {
543  ownPointCnt = tmpAnz.ownPointCnt;
544  mem4 = i;
545  }
546  }
547  }
548  }
549  }
550  if (this.mReversi.getMasuStsEna(color, this.mEdge[i].y, this.mEdge[i].x) == 2) {
551  mem = i;
552  }
553  }
554  if (mem2 != -1) {
555  if (endZone != 0) { // 終盤なら枚数重視
556  if (mem3 != -1) {
557  mem2 = mem3;
558  }
559  } else {
560  if (mem4 != -1) {
561  mem2 = mem4;
562  }
563  }
564  mem = mem2;
565  }
566  if (mem == -1) mem = r.Next(kadocnt);
567  // *** 置いても平気な角があればそこに置く*** //
568  for (var i = 0; i < kadocnt; i++) {
569  if (this.mReversi.checkEdge(color, this.mEdge[i].y, this.mEdge[i].x) != 0) {
570  if ((cpuflg0 == 0) && (cpuflg1 == 0) && (cpuflg2 == 0)) {
571  cpuflg3 = 1;
572  rcnt2 = i;
573  }
574  }
575  }
576  }
577  if ((cpuflg1 == 0) && (cpuflg2 == 0) && (cpuflg0 == 0) && (cpuflg3 == 0)) {
578  rcnt2 = mem;
579  }
580  if (rcnt1 != 0) {
581  setY = this.mCpu[rcnt2].y;
582  setX = this.mCpu[rcnt2].x;
583  } else if (kadocnt != 0) {
584  setY = this.mEdge[rcnt2].y;
585  setX = this.mEdge[rcnt2].x;
586  }
587  }
588  }
589 
590  if (this.mReversi.setMasuSts(color, setY, setX) == 0) {
591  if (this.mSetting.mType == ReversiConst.DEF_TYPE_HARD) this.mReversi.AnalysisReversi(this.mPassEnaB, this.mPassEnaW);
592  this.sendDrawMsg(setY, setX); // 描画
593  update = 1;
594  }
595  }
596  } else {
597  break;
598  }
599  }
600  if (update == 1) {
602  if (this.mSetting.mAssist == ReversiConst.DEF_ASSIST_ON) {
603  // *** メッセージ送信 *** //
605  }
606  }
607 
608  return update;
609  }
610 
620  public void drawUpdate(int assist)
621  {
622  if (assist == ReversiConst.DEF_ASSIST_ON) {
623  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
624  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
625  this.sendDrawInfoMsg(i, j);
626  }
627  }
628  }
629  var waitTime = this.mSetting.mPlayDrawInterVal;
630  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
631  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
632  if(this.mReversi.getMasuSts(i,j) != this.mReversi.getMasuStsOld(i,j)){
633  System.Threading.Thread.Sleep(waitTime);
634  this.sendDrawMsg(i, j);
635  }
636  }
637  }
638  // *** メッセージ送信 *** //
640  // *** メッセージ送信 *** //
642  }
643 
653  public void drawUpdateForcibly(int assist)
654  {
655  // *** メッセージ送信 *** //
657  if (assist == ReversiConst.DEF_ASSIST_ON) {
658  // *** メッセージ送信 *** //
660  } else {
661  // *** メッセージ送信 *** //
663  }
664  // *** メッセージ送信 *** //
666  // *** メッセージ送信 *** //
668  }
669 
678  public void reset()
679  {
680  this.mPassEnaB = 0;
681  this.mPassEnaW = 0;
682  if (this.mSetting.mGameSpd == ReversiConst.DEF_GAME_SPD_FAST) {
683  this.mSetting.mPlayDrawInterVal = ReversiConst.DEF_GAME_SPD_FAST_VAL; // 描画のインターバル(msec)
684  this.mSetting.mPlayCpuInterVal = ReversiConst.DEF_GAME_SPD_FAST_VAL2; // CPU対戦時のインターバル(msec)
685  } else if (this.mSetting.mGameSpd == ReversiConst.DEF_GAME_SPD_MID) {
686  this.mSetting.mPlayDrawInterVal = ReversiConst.DEF_GAME_SPD_MID_VAL; // 描画のインターバル(msec)
687  this.mSetting.mPlayCpuInterVal = ReversiConst.DEF_GAME_SPD_MID_VAL2; // CPU対戦時のインターバル(msec)
688  } else {
689  this.mSetting.mPlayDrawInterVal = ReversiConst.DEF_GAME_SPD_SLOW_VAL; // 描画のインターバル(msec)
690  this.mSetting.mPlayCpuInterVal = ReversiConst.DEF_GAME_SPD_SLOW_VAL2; // CPU対戦時のインターバル(msec)
691  }
692 
693  this.mCurColor = this.mSetting.mPlayer;
694  if (this.mSetting.mMode == ReversiConst.DEF_MODE_TWO) this.mCurColor = ReversiConst.REVERSI_STS_BLACK;
695 
696  this.mReversi.setMasuCnt(this.mSetting.mMasuCnt); // マスの数設定
697 
698  this.mReversi.reset();
699  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) {
700  if (this.mCurColor == ReversiConst.REVERSI_STS_WHITE) {
701  var pCnt = this.mReversi.getPointCnt(ReversiConst.REVERSI_STS_BLACK);
702  ReversiPoint pInfo = this.mReversi.getPoint(ReversiConst.REVERSI_STS_BLACK, r.Next(pCnt));
703  if (pInfo != null) {
704  this.mReversi.setMasuSts(ReversiConst.REVERSI_STS_BLACK, pInfo.y, pInfo.x);
705  if (this.mSetting.mType == ReversiConst.DEF_TYPE_HARD) this.mReversi.AnalysisReversi(this.mPassEnaB, this.mPassEnaW);
706  }
707  }
708  }
709 
710  this.mPlayLock = 1;
711  this.mGameEndSts = 0;
712 
713  this.drawUpdateForcibly(this.mSetting.mAssist);
714 
715  // *** 終了通知 *** //
716  // *** メッセージ送信 *** //
718  }
719 
728  public int gameEndAnimExec()
729  {
730  int bCnt, wCnt;
731  int ret = 0;
732 
733  if (this.mSetting.mEndAnim == ReversiConst.DEF_END_ANIM_ON) {
734  bCnt = this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_BLACK);
735  wCnt = this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_WHITE);
736 
737  // *** 色、コマ数表示消去 *** //
738  // *** メッセージ送信 *** //
740  // *** メッセージ送信 *** //
742 
743  System.Threading.Thread.Sleep(this.mSetting.mEndInterVal);
744  // *** マス消去 *** //
745  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
746  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
747  this.mReversi.setMasuStsForcibly(ReversiConst.REVERSI_STS_NONE, i, j);
748  }
749  }
750  // *** メッセージ送信 *** //
752 
753  // *** マス描画 *** //
754  int bCnt2, wCnt2, bEnd, wEnd;
755  bCnt2 = 0;
756  wCnt2 = 0;
757  bEnd = 0;
758  wEnd = 0;
759  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
760  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
761  if (bCnt2 < bCnt) {
762  bCnt2++;
764  this.sendDrawMsg(i, j);
765  } else {
766  bEnd = 1;
767  }
768  if (wCnt2 < wCnt) {
769  wCnt2++;
770  this.mReversi.setMasuStsForcibly(ReversiConst.REVERSI_STS_WHITE, (this.mSetting.mMasuCnt - 1) - i, (this.mSetting.mMasuCnt - 1) - j);
771  this.sendDrawMsg((this.mSetting.mMasuCnt - 1) - i, (this.mSetting.mMasuCnt - 1) - j);
772  } else {
773  wEnd = 1;
774  }
775  if (bEnd == 1 && wEnd == 1) {
776  break;
777  }else{
778  System.Threading.Thread.Sleep(this.mSetting.mEndDrawInterVal);
779  }
780  }
781  }
782  ret = 0;
783  }
784  return ret;
785  }
786 
797  public void sendDrawMsg(int y, int x)
798  {
799  ReversiPoint mTmpPoint = new ReversiPoint();
800  mTmpPoint.y = y;
801  mTmpPoint.x = x;
802  // *** メッセージ送信 *** //
803  this.execMessage(ReversiConst.LC_MSG_DRAW, mTmpPoint);
804  }
805 
816  public void sendDrawInfoMsg(int y, int x)
817  {
818  ReversiPoint mTmpPoint = new ReversiPoint();
819  mTmpPoint.y = y;
820  mTmpPoint.x = x;
821  // *** メッセージ送信 *** //
822  this.execMessage(ReversiConst.LC_MSG_DRAW_INFO, mTmpPoint);
823  }
824 
835  private void execMessage(int what, Object obj)
836  {
837  int dMode, dBack, dCnt;
838  if (what == ReversiConst.LC_MSG_DRAW) {
839  // *** マス描画 *** //
840  ReversiPoint msgPoint = (ReversiPoint)obj;
841  dMode = this.mReversi.getMasuSts(msgPoint.y, msgPoint.x);
842  dBack = this.mReversi.getMasuStsEna(this.mCurColor, msgPoint.y, msgPoint.x);
843  dCnt = this.mReversi.getMasuStsCnt(this.mCurColor, msgPoint.y, msgPoint.x);
844  this.DrawSingleLocal(msgPoint.y, msgPoint.x, dMode, dBack, dCnt.ToString());
845  } else if (what == ReversiConst.LC_MSG_ERASE) {
846  // *** マス消去 *** //
847  ReversiPoint msgPoint = (ReversiPoint)obj;
848  this.DrawSingleLocal(msgPoint.y, msgPoint.x, 0, 0, "0");
849  } else if (what == ReversiConst.LC_MSG_DRAW_INFO) {
850  // *** マス情報描画 *** //
851  ReversiPoint msgPoint = (ReversiPoint)obj;
852  dMode = this.mReversi.getMasuSts(msgPoint.y, msgPoint.x);
853  dBack = this.mReversi.getMasuStsEna(this.mCurColor, msgPoint.y, msgPoint.x);
854  dCnt = this.mReversi.getMasuStsCnt(this.mCurColor, msgPoint.y, msgPoint.x);
855  this.DrawSingleLocal(msgPoint.y, msgPoint.x, dMode, dBack, dCnt.ToString());
856  } else if (what == ReversiConst.LC_MSG_ERASE_INFO) {
857  // *** マス情報消去 *** //
858  ReversiPoint msgPoint = (ReversiPoint)obj;
859  dMode = this.mReversi.getMasuSts(msgPoint.y, msgPoint.x);
860  this.DrawSingleLocal(msgPoint.y, msgPoint.x, dMode, 0, "0");
861  } else if (what == ReversiConst.LC_MSG_DRAW_ALL) {
862  // *** 全マス描画 *** //
863  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
864  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
865  dMode = this.mReversi.getMasuSts(i, j);
866  dBack = this.mReversi.getMasuStsEna(this.mCurColor, i, j);
867  dCnt = this.mReversi.getMasuStsCnt(this.mCurColor, i, j);
868  this.DrawSingleLocal(i, j, dMode, dBack, dCnt.ToString());
869  }
870  }
871  } else if (what == ReversiConst.LC_MSG_ERASE_ALL) {
872  // *** 全マス消去 *** //
873  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
874  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
875  this.DrawSingleLocal(i, j, 0, 0, "0");
876  }
877  }
878  } else if (what == ReversiConst.LC_MSG_DRAW_INFO_ALL) {
879  // *** 全マス情報描画 *** //
880  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
881  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
882  dMode = this.mReversi.getMasuSts(i, j);
883  dBack = this.mReversi.getMasuStsEna(this.mCurColor, i, j);
884  dCnt = this.mReversi.getMasuStsCnt(this.mCurColor, i, j);
885  this.DrawSingleLocal(i, j, dMode, dBack, dCnt.ToString());
886  }
887  }
888  } else if (what == ReversiConst.LC_MSG_ERASE_INFO_ALL) {
889  // *** 全マス情報消去 *** //
890  for (var i = 0; i < this.mSetting.mMasuCnt; i++) {
891  for (var j = 0; j < this.mSetting.mMasuCnt; j++) {
892  dMode = this.mReversi.getMasuSts(i, j);
893  this.DrawSingleLocal(i, j, dMode, 0, "0");
894  }
895  }
896  } else if (what == ReversiConst.LC_MSG_DRAW_END) {
897  this.mPlayLock = 0;
898  } else if (what == ReversiConst.LC_MSG_CUR_COL) {
899  string tmpStr = "";
900  if (this.mSetting.mMode == ReversiConst.DEF_MODE_ONE) {
901  if (this.mCurColor == ReversiConst.REVERSI_STS_BLACK) tmpStr = "あなたはプレイヤー1です ";
902  else tmpStr = "あなたはプレイヤー2です ";
903  } else {
904  if (this.mCurColor == ReversiConst.REVERSI_STS_BLACK) tmpStr = "プレイヤー1の番です ";
905  else tmpStr = "プレイヤー2の番です ";
906  }
907  this.CurColMsgLocal(tmpStr);
908  } else if (what == ReversiConst.LC_MSG_CUR_COL_ERASE) {
909  this.CurColMsgLocal("");
910  } else if (what == ReversiConst.LC_MSG_CUR_STS) {
911  string tmpStr = "プレイヤー1 = " + this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_BLACK) + " プレイヤー2 = " + this.mReversi.getBetCnt(ReversiConst.REVERSI_STS_WHITE);
912  this.CurStsMsgLocal(tmpStr);
913  } else if (what == ReversiConst.LC_MSG_CUR_STS_ERASE) {
914  this.CurStsMsgLocal("");
915  } else if (what == ReversiConst.LC_MSG_MSG_DLG) {
916  } else if (what == ReversiConst.LC_MSG_DRAW_ALL_RESET) {
917  }
918  }
919 
930  private void ViewMsgDlgLocal(string title , string msg)
931  {
932  if(this.viewMsgDlg != null) this.viewMsgDlg(title, msg);
933  }
934 
948  private void DrawSingleLocal(int y, int x, int sts, int bk, string text)
949  {
950  if(this.drawSingle != null) this.drawSingle(y, x, sts, bk, text);
951  }
952 
962  private void CurColMsgLocal(string text)
963  {
964  if(this.curColMsg != null) this.curColMsg(text);
965  }
966 
976  private void CurStsMsgLocal(string text)
977  {
978  if(this.curStsMsg != null) this.curStsMsg(text);
979  }
980  }
981 }
ReversiPoint [] _mCpu
CPU用ワーク
Definition: ReversiPlay.cs:43
const int DEF_TYPE_EASY
CPU 弱い
Definition: ReversiConst.cs:36
void reset()
リセット
Definition: MyReversi.cs:243
CurColMsg _curColMsg
現在の色メッセージコールバック
Definition: ReversiPlay.cs:51
ReversiAnz getPointAnz(int color, int y, int x)
ポイント座標解析取得
Definition: MyReversi.cs:1291
const int DEF_TYPE_NOR
CPU 普通
Definition: ReversiConst.cs:37
const int LC_MSG_ERASE_INFO
マス情報消去
Definition: ReversiConst.cs:90
const int LC_MSG_DRAW
マス描画
Definition: ReversiConst.cs:87
const int REVERSI_STS_WHITE
Definition: ReversiConst.cs:82
アプリ設定クラス
Definition: ReversiConst.cs:30
const int DEF_GAME_SPD_SLOW_VAL
ゲームスピード 遅い
Definition: ReversiConst.cs:52
void DrawSingleLocal(int y, int x, int sts, int bk, string text)
1マス描画
Definition: ReversiPlay.cs:948
const int REVERSI_STS_BLACK
Definition: ReversiConst.cs:81
void reset()
リセット処理
Definition: ReversiPlay.cs:678
int getEdgeSideZero(int y, int x)
指定座標が角か取得
Definition: MyReversi.cs:1430
int setMasuCnt(int cnt)
マスの数変更
Definition: MyReversi.cs:1154
int _mPassEnaB
黒のパス有効フラグ
Definition: ReversiPlay.cs:45
const int LC_MSG_ERASE_ALL
全マス消去
Definition: ReversiConst.cs:92
ReversiSetting _mSetting
リバーシ設定クラス
Definition: ReversiPlay.cs:41
const int LC_MSG_CUR_COL
現在の色
Definition: ReversiConst.cs:96
int _mPassEnaW
白のパス有効フラグ
Definition: ReversiPlay.cs:46
const int LC_MSG_DRAW_END
描画終わり
Definition: ReversiConst.cs:95
void CurStsMsgLocal(string text)
現在のステータスメッセージ
Definition: ReversiPlay.cs:976
const int DEF_GAME_SPD_MID_VAL
ゲームスピード 普通
Definition: ReversiConst.cs:51
void execMessage(int what, Object obj)
メッセージ
Definition: ReversiPlay.cs:835
const int DEF_GAME_SPD_FAST
ゲームスピード 早い
Definition: ReversiConst.cs:46
int getMasuStsEna(int color, int y, int x)
指定座標に指定色を置けるかチェック
Definition: MyReversi.cs:1023
int getGameEndSts()
ゲーム終了かチェック
Definition: MyReversi.cs:1085
const int DEF_GAME_SPD_MID
ゲームスピード 普通
Definition: ReversiConst.cs:47
int getMasuSts(int y, int x)
マスステータスを取得
Definition: MyReversi.cs:988
int setMasuSts(int color, int y, int x)
指定座標にコマを置く
Definition: MyReversi.cs:1104
int _mGameEndSts
ゲーム終了ステータス
Definition: ReversiPlay.cs:47
void AnalysisReversi(int bPassEna, int wPassEna)
解析を行う
Definition: MyReversi.cs:948
ReversiPlay()
コンストラクタ
Definition: ReversiPlay.cs:132
void sendDrawMsg(int y, int x)
描画メッセージ送信
Definition: ReversiPlay.cs:797
リバーシ解析クラス
Definition: ReversiAnz.cs:30
ReversiPlay Clone()
コピー
Definition: ReversiPlay.cs:152
リバーシポイント
Definition: ReversiPoint.cs:30
const int DEF_GAME_SPD_FAST_VAL
ゲームスピード 早い
Definition: ReversiConst.cs:50
ViewMsgDlg _viewMsgDlg
メッセージコールバック
Definition: ReversiPlay.cs:49
リバーシクラス
Definition: MyReversi.cs:30
DrawSingle _drawSingle
描画コールバック
Definition: ReversiPlay.cs:50
void reversiPlayEnd()
リバーシプレイ終了
Definition: ReversiPlay.cs:291
const int LC_MSG_CUR_STS_ERASE
現在のステータス消去
Definition: ReversiConst.cs:99
CurStsMsg _curStsMsg
現在のステータスメッセージコールバック
Definition: ReversiPlay.cs:52
int getEdgeSideTwo(int y, int x)
指定座標が角の二つ手前か取得
Definition: MyReversi.cs:1486
const int DEF_TYPE_HARD
CPU 強い
Definition: ReversiConst.cs:38
void ViewMsgDlgLocal(string title, string msg)
メッセージダイアログ
Definition: ReversiPlay.cs:930
void CurColMsgLocal(string text)
現在の色メッセージ
Definition: ReversiPlay.cs:962
int gameEndAnimExec()
ゲーム終了アニメーション
Definition: ReversiPlay.cs:728
void reversiPlay(int y, int x)
リバーシプレイ
Definition: ReversiPlay.cs:167
const int DEF_MODE_ONE
一人対戦
Definition: ReversiConst.cs:33
ReversiPoint [] _mEdge
CPU用角マスワーク
Definition: ReversiPlay.cs:44
int getColorEna(int color)
指定色が現在置ける場所があるかチェック
Definition: MyReversi.cs:1063
int setMasuStsForcibly(int color, int y, int x)
指定座標にコマを強制的に置く
Definition: MyReversi.cs:1136
const int DEF_END_ANIM_ON
終了アニメーション ON
Definition: ReversiConst.cs:59
const int DEF_ASSIST_ON
アシスト ON
Definition: ReversiConst.cs:44
ReversiPoint getPoint(int color, int num)
ポイント座標取得
Definition: MyReversi.cs:1179
int getPassEna(int color, int y, int x)
パス判定
Definition: MyReversi.cs:1237
リバーシプレイクラス
Definition: ReversiPlay.cs:30
const int DEF_GAME_SPD_FAST_VAL2
ゲームスピード 早い
Definition: ReversiConst.cs:54
int reversiPlayCpu(int color, int cpuEna)
リバーシプレイコンピューター
Definition: ReversiPlay.cs:361
const int DEF_MODE_TWO
二人対戦
Definition: ReversiConst.cs:34
const int REVERSI_STS_NONE
コマ無し
Definition: ReversiConst.cs:80
int _mPlayLock
プレイロック
Definition: ReversiPlay.cs:48
void reversiPlaySub(int cpuEna, int tmpCol)
リバーシプレイサブ
Definition: ReversiPlay.cs:261
const int LC_MSG_DRAW_ALL
全マス描画
Definition: ReversiConst.cs:91
const int LC_MSG_DRAW_ALL_RESET
全マスビットマップインスタンスクリア
int getMasuStsCnt(int color, int y, int x)
指定座標の獲得コマ数取得
Definition: MyReversi.cs:1044
const int LC_MSG_DRAW_INFO_ALL
全マス情報描画
Definition: ReversiConst.cs:93
void sendDrawInfoMsg(int y, int x)
情報描画メッセージ送信
Definition: ReversiPlay.cs:816
int _mCurColor
現在の色
Definition: ReversiPlay.cs:42
アプリ設定クラス
int getEdgeSideOne(int y, int x)
指定座標が角の一つ手前か取得
Definition: MyReversi.cs:1454
const int LC_MSG_ERASE_INFO_ALL
全マス情報消去
Definition: ReversiConst.cs:94
MyReversi _mReversi
リバーシクラス
Definition: ReversiPlay.cs:40
int getBetCnt(int color)
コマ数取得
Definition: MyReversi.cs:1215
const int LC_MSG_CUR_STS
現在のステータス
Definition: ReversiConst.cs:98
const int DEF_GAME_SPD_MID_VAL2
ゲームスピード 普通
Definition: ReversiConst.cs:55
int getMasuStsOld(int y, int x)
以前のマスステータスを取得
Definition: MyReversi.cs:1005
const int LC_MSG_ERASE
マス消去
Definition: ReversiConst.cs:88
const int DEF_MASU_CNT_MAX_VAL
マス縦横最大
Definition: ReversiConst.cs:78
void drawUpdateForcibly(int assist)
マス描画強制更新
Definition: ReversiPlay.cs:653
System.Random r
乱数
Definition: ReversiPlay.cs:53
const int LC_MSG_MSG_DLG
メッセージダイアログ
const int DEF_GAME_SPD_SLOW_VAL2
ゲームスピード 遅い
Definition: ReversiConst.cs:56
void drawUpdate(int assist)
マス描画更新
Definition: ReversiPlay.cs:620
void reversiPlayPass(int color)
リバーシプレイパス
Definition: ReversiPlay.cs:339
int getPointCnt(int color)
ポイント座標数取得
Definition: MyReversi.cs:1198
const int LC_MSG_DRAW_INFO
マス情報描画
Definition: ReversiConst.cs:89
const int LC_MSG_CUR_COL_ERASE
現在の色消去
Definition: ReversiConst.cs:97
const int DEF_ASSIST_OFF
アシスト OFF
Definition: ReversiConst.cs:43
int getEdgeSideThree(int y, int x)
指定座標が角の三つ以上手前か取得
Definition: MyReversi.cs:1518
int checkEdge(int color, int y, int x)
角の隣に置いても角を取られないマス検索
Definition: MyReversi.cs:1312