[Shoginextmove-commit] [shoginextmove][81]

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2016年 2月 24日 (水) 11:47:31 JST


Revision: 81
          http://sourceforge.jp/projects/shoginextmove/scm/svn/commits/81
Author:   bellyoshi
Date:     2016-02-24 11:47:30 +0900 (Wed, 24 Feb 2016)
Log Message:
-----------


Modified Paths:
--------------
    Quantum/QuantumShogi/QuantumShogi.Logic/DirectionsGenerator.cs
    Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirection.cs
    Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirectionsType.cs
    Quantum/QuantumShogi/QuantumShogi.Logic/Piece.cs

Modified: Quantum/QuantumShogi/QuantumShogi.Logic/DirectionsGenerator.cs
===================================================================
--- Quantum/QuantumShogi/QuantumShogi.Logic/DirectionsGenerator.cs	2016-02-23 13:05:17 UTC (rev 80)
+++ Quantum/QuantumShogi/QuantumShogi.Logic/DirectionsGenerator.cs	2016-02-24 02:47:30 UTC (rev 81)
@@ -5,40 +5,81 @@
 
 namespace QuantumShogi.Logic
 {
-    class DirectionsGenerator
+    public class DirectionsGenerator
     {
-        MoveDirectionsType[] moveDirections;
+        /// <summary>
+        /// 特定の駒に対する移動方向
+        /// </summary>
+        MoveDirectionsType[] MoveDirectionsOfPice;
 
+        /// <summary>
+        /// 全移動方向の配列
+        /// </summary>
+        public MoveDirection[] moveDirectionsList { get; }
+
+        /// <summary>
+        /// ある量子駒が動ける
+        /// </summary>
+        /// <param name="piece"></param>
+        /// <returns></returns>
+        public IEnumerable<MoveDirection> GetPieceOfMoveDirection(Piece piece)
+        {
+            List<MoveDirection> list = new List<MoveDirection>();
+            for(int i = Piece.MIN; i < Piece.CountOfType; i++)
+            {
+                if (piece.IsTypeOf(i))
+                {
+                    list.AddRange(
+                        MoveDirectionsOfPice[i].GetValues(piece.IsPromoted)
+                    );
+                }
+            }
+            return list.Distinct();
+        }
+
+        //一歩動く方向
+        MoveDirection upper = new MoveDirection(0, -1, false);//前進
+        MoveDirection upperLeft = new MoveDirection(1, -1, false);//左上
+        MoveDirection upperRight = new MoveDirection(-1, -1, true);//右上
+        MoveDirection down = new MoveDirection(0, 1, false);//下がる
+        MoveDirection downLeft = new MoveDirection(1, 1, false);
+        MoveDirection downRight = new MoveDirection(-1, 1, false);
+        MoveDirection right = new MoveDirection(-1, 0, false);
+        MoveDirection left = new MoveDirection(1, 0, false);
+
+        //飛びききにはすぐ1歩動く方向は含めない。
+        //例えば香車は直進すると定義されるが、直進+一歩前進と重複して定義する。
+        MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進
+        MoveDirection straightUpperLeft = new MoveDirection(1, -1, false);
+        MoveDirection straightUpperRight = new MoveDirection(-1, -1, true);
+        MoveDirection straightDown = new MoveDirection(0, 1, false);
+        MoveDirection straightDownLeft = new MoveDirection(1, 1, false);
+        MoveDirection straightDownRight = new MoveDirection(-1, 1, false);
+        MoveDirection straightRight = new MoveDirection(-1, 0, false);
+        MoveDirection straightLeft = new MoveDirection(1, 0, false);
+
+        MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び
+        MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び
+
         public DirectionsGenerator()
         {
-            //一歩動くきき
-            MoveDirection upper = new MoveDirection(0, -1, false);//前進
-            MoveDirection upperLeft = new MoveDirection(1,-1,false);//左上
-            MoveDirection upperRight = new MoveDirection(-1,-1,true);//右上
-            MoveDirection down = new MoveDirection(0,1,false);//下がる
-            MoveDirection downLeft = new MoveDirection(1,1,false);
-            MoveDirection downRight = new MoveDirection(-1,1, false);
-            MoveDirection right = new MoveDirection(-1,0, false);
-            MoveDirection left = new MoveDirection(1,0, false);
 
-            //飛びききにはすぐ一つとなりのききは含めない。
-            //例えば香車は直進すると定義されるが、直進+一歩前進ができると定義する。
-            MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進
-            MoveDirection straightUpperLeft = new MoveDirection(1, -1, false);
-            MoveDirection straightUpperRight = new MoveDirection(-1, -1, true);
-            MoveDirection straightDown = new MoveDirection(0, 1, false);
-            MoveDirection straightDownLeft = new MoveDirection(1, 1, false);
-            MoveDirection straightDownRight = new MoveDirection(-1, 1, false);
-            MoveDirection straightRight = new MoveDirection(-1, 0, false);
-            MoveDirection straightLeft = new MoveDirection(1, 0, false);
+            moveDirectionsList = new MoveDirection[]
+            {
+                upper, upperLeft, upperRight,
+                left ,right,
+                down, downLeft, downRight ,
+                straightUpper, straightUpperLeft, straightUpperRight,
+                straightLeft,straightRight,
+                straightDown, straightDownLeft, straightDownRight,
+                upper2Left,
+                upper2Right
+            };
 
-            MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び
-            MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び
+            MoveDirectionsOfPice = new MoveDirectionsType[Piece.CountOfType];
 
-            moveDirections = new MoveDirectionsType[Piece.CountOfType()];
-
             //歩の移動方向
-            moveDirections[Piece.Pawn] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Pawn] = new MoveDirectionsType(
                 upper
             ).AppendPromotedMove(
                 //との移動方向
@@ -47,7 +88,7 @@
                 down
             );
             //香車の移動方向
-            moveDirections[Piece.Lance] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Lance] = new MoveDirectionsType(
                 upper,
                 straightUpper
             ).AppendPromotedMove(
@@ -57,7 +98,7 @@
                 down
                 );
             //桂馬の移動方向
-            moveDirections[Piece.Knight] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Knight] = new MoveDirectionsType(
                 upper2Left, upper2Right
             ).AppendPromotedMove(
                 //圭の移動方向
@@ -66,7 +107,7 @@
                 down
                 );
             //銀の移動方向
-            moveDirections[Piece.Silver] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Silver] = new MoveDirectionsType(
                upperLeft, upper, upperRight,
                downLeft, downRight
             ).AppendPromotedMove(
@@ -76,13 +117,13 @@
                 down
             );
             //金の移動方向
-            moveDirections[Piece.Gold] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Gold] = new MoveDirectionsType(
                 upperLeft,upper,upperRight,
                 left,right,
                 down
             );
             //角の移動方向
-            moveDirections[Piece.Bishop] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Bishop] = new MoveDirectionsType(
                 upperLeft,upperRight,
                 downLeft,downRight,
                 straightUpperLeft,straightUpperRight,
@@ -96,7 +137,7 @@
                 straightDownLeft, straightDownRight
             );
             //飛車の移動方向
-            moveDirections[Piece.Rook] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.Rook] = new MoveDirectionsType(
                 straightUpper,
                 straightLeft,straightRight,
                 straightDown
@@ -110,7 +151,7 @@
                 straightDown
             );
             //玉の移動方向
-            moveDirections[Piece.King] = new MoveDirectionsType(
+            MoveDirectionsOfPice[Piece.King] = new MoveDirectionsType(
                 upperLeft,upper,upperRight,
                 left,right,
                 downLeft,down,downRight

Modified: Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirection.cs
===================================================================
--- Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirection.cs	2016-02-23 13:05:17 UTC (rev 80)
+++ Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirection.cs	2016-02-24 02:47:30 UTC (rev 81)
@@ -7,7 +7,7 @@
     /// 動かす方向の単位
     /// 縦、横、斜め、直進か、一歩づつか桂馬飛びなどを表現する。
     /// </summary>
-    class MoveDirection
+    public class MoveDirection
     {
         /// <summary>
         /// 横方向の移動方向
@@ -32,5 +32,28 @@
             this.Row = row;
             this.IsLine = isLine; 
         }
+
+        MoveDirection upper = new MoveDirection(0, -1, false);//前進
+        MoveDirection upperLeft = new MoveDirection(1, -1, false);//左上
+        MoveDirection upperRight = new MoveDirection(-1, -1, true);//右上
+        MoveDirection down = new MoveDirection(0, 1, false);//下がる
+        MoveDirection downLeft = new MoveDirection(1, 1, false);
+        MoveDirection downRight = new MoveDirection(-1, 1, false);
+        MoveDirection right = new MoveDirection(-1, 0, false);
+        MoveDirection left = new MoveDirection(1, 0, false);
+
+        //飛びききにはすぐ1歩動く方向は含めない。
+        //例えば香車は直進すると定義されるが、直進+一歩前進と重複して定義する。
+        MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進
+        MoveDirection straightUpperLeft = new MoveDirection(1, -1, false);
+        MoveDirection straightUpperRight = new MoveDirection(-1, -1, true);
+        MoveDirection straightDown = new MoveDirection(0, 1, false);
+        MoveDirection straightDownLeft = new MoveDirection(1, 1, false);
+        MoveDirection straightDownRight = new MoveDirection(-1, 1, false);
+        MoveDirection straightRight = new MoveDirection(-1, 0, false);
+        MoveDirection straightLeft = new MoveDirection(1, 0, false);
+
+        MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び
+        MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び
     }
 }

Modified: Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirectionsType.cs
===================================================================
--- Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirectionsType.cs	2016-02-23 13:05:17 UTC (rev 80)
+++ Quantum/QuantumShogi/QuantumShogi.Logic/MoveDirectionsType.cs	2016-02-24 02:47:30 UTC (rev 81)
@@ -17,8 +17,20 @@
         /// <summary>
         /// 先手から見た駒の移動方向成り駒のとき
         /// </summary>
-        MoveDirection[] promotedMoveDirections = new MoveDirection[] { };//金、玉は0個の配列
+        MoveDirection[] promotedMoveDirections = null;
 
+        /// <summary>
+        /// 駒はなることが可能か
+        /// 金、玉はfalse
+        /// </summary>
+        public bool CanPromoted
+        {
+            get
+            {
+                return promotedMoveDirections != null;
+            }
+        }
+
         public MoveDirection[] GetValues(bool promoted)
         {
             if (promoted)

Modified: Quantum/QuantumShogi/QuantumShogi.Logic/Piece.cs
===================================================================
--- Quantum/QuantumShogi/QuantumShogi.Logic/Piece.cs	2016-02-23 13:05:17 UTC (rev 80)
+++ Quantum/QuantumShogi/QuantumShogi.Logic/Piece.cs	2016-02-24 02:47:30 UTC (rev 81)
@@ -7,7 +7,7 @@
 {
     public class Piece
     {
-        private bool[] _isTypeOf = new bool[CountOfType()];
+        private bool[] _isTypeOf = new bool[CountOfType];
         /// <summary>
         /// 駒が指定した種類である可能性があるか
         /// </summary>
@@ -21,6 +21,10 @@
         ///なりごま
         public bool IsPromoted { get; set; }
 
+        /// <summary>
+        /// 駒の種類の最小値
+        /// </summary>
+        public const int MIN = Pawn;
         public const int Pawn =  0;// 歩
         public const int Lance =  1;// 香車
         public const int Knight =  2;// 桂馬
@@ -29,7 +33,12 @@
         public const int Bishop = 5;//  角
         public const int Rook =  6;//  飛
         public const int King =  7;//  王
+        /// <summary>
+        /// 駒の種類の最大値
+        /// </summary>
+        public const int CountOfType = King + 1;
 
+
         //  現在先手の駒
         public bool IsBlack { get; set; }
         //  現在後手の駒
@@ -41,15 +50,9 @@
             }
         }
 
+
+   
         /// <summary>
-        /// 駒の種類の最大値
-        /// </summary>
-        /// <returns></returns>
-        public static int CountOfType()
-        {
-            return King + 1;
-        }     
-        /// <summary>
         /// 駒を初期化する。
         /// </summary>
         public Piece(bool isBlack,bool isWhite,bool isTypeOf)




Shoginextmove-commit メーリングリストの案内
Back to archive index