| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | { |
| 8 | 8 | public class Piece |
| 9 | 9 | { |
| 10 | - private bool[] _isTypeOf = new bool[CountOfType()]; | |
| 10 | + private bool[] _isTypeOf = new bool[CountOfType]; | |
| 11 | 11 | /// <summary> |
| 12 | 12 | /// 駒が指定した種類である可能性があるか |
| 13 | 13 | /// </summary> |
| @@ -21,6 +21,10 @@ | ||
| 21 | 21 | ///なりごま |
| 22 | 22 | public bool IsPromoted { get; set; } |
| 23 | 23 | |
| 24 | + /// <summary> | |
| 25 | + /// 駒の種類の最小値 | |
| 26 | + /// </summary> | |
| 27 | + public const int MIN = Pawn; | |
| 24 | 28 | public const int Pawn = 0;// 歩 |
| 25 | 29 | public const int Lance = 1;// 香車 |
| 26 | 30 | public const int Knight = 2;// 桂馬 |
| @@ -29,7 +33,12 @@ | ||
| 29 | 33 | public const int Bishop = 5;// 角 |
| 30 | 34 | public const int Rook = 6;// 飛 |
| 31 | 35 | public const int King = 7;// 王 |
| 36 | + /// <summary> | |
| 37 | + /// 駒の種類の最大値 | |
| 38 | + /// </summary> | |
| 39 | + public const int CountOfType = King + 1; | |
| 32 | 40 | |
| 41 | + | |
| 33 | 42 | // 現在先手の駒 |
| 34 | 43 | public bool IsBlack { get; set; } |
| 35 | 44 | // 現在後手の駒 |
| @@ -41,15 +50,9 @@ | ||
| 41 | 50 | } |
| 42 | 51 | } |
| 43 | 52 | |
| 53 | + | |
| 54 | + | |
| 44 | 55 | /// <summary> |
| 45 | - /// 駒の種類の最大値 | |
| 46 | - /// </summary> | |
| 47 | - /// <returns></returns> | |
| 48 | - public static int CountOfType() | |
| 49 | - { | |
| 50 | - return King + 1; | |
| 51 | - } | |
| 52 | - /// <summary> | |
| 53 | 56 | /// 駒を初期化する。 |
| 54 | 57 | /// </summary> |
| 55 | 58 | public Piece(bool isBlack,bool isWhite,bool isTypeOf) |
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | /// 動かす方向の単位 |
| 8 | 8 | /// 縦、横、斜め、直進か、一歩づつか桂馬飛びなどを表現する。 |
| 9 | 9 | /// </summary> |
| 10 | - class MoveDirection | |
| 10 | + public class MoveDirection | |
| 11 | 11 | { |
| 12 | 12 | /// <summary> |
| 13 | 13 | /// 横方向の移動方向 |
| @@ -32,5 +32,28 @@ | ||
| 32 | 32 | this.Row = row; |
| 33 | 33 | this.IsLine = isLine; |
| 34 | 34 | } |
| 35 | + | |
| 36 | + MoveDirection upper = new MoveDirection(0, -1, false);//前進 | |
| 37 | + MoveDirection upperLeft = new MoveDirection(1, -1, false);//左上 | |
| 38 | + MoveDirection upperRight = new MoveDirection(-1, -1, true);//右上 | |
| 39 | + MoveDirection down = new MoveDirection(0, 1, false);//下がる | |
| 40 | + MoveDirection downLeft = new MoveDirection(1, 1, false); | |
| 41 | + MoveDirection downRight = new MoveDirection(-1, 1, false); | |
| 42 | + MoveDirection right = new MoveDirection(-1, 0, false); | |
| 43 | + MoveDirection left = new MoveDirection(1, 0, false); | |
| 44 | + | |
| 45 | + //飛びききにはすぐ1歩動く方向は含めない。 | |
| 46 | + //例えば香車は直進すると定義されるが、直進+一歩前進と重複して定義する。 | |
| 47 | + MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進 | |
| 48 | + MoveDirection straightUpperLeft = new MoveDirection(1, -1, false); | |
| 49 | + MoveDirection straightUpperRight = new MoveDirection(-1, -1, true); | |
| 50 | + MoveDirection straightDown = new MoveDirection(0, 1, false); | |
| 51 | + MoveDirection straightDownLeft = new MoveDirection(1, 1, false); | |
| 52 | + MoveDirection straightDownRight = new MoveDirection(-1, 1, false); | |
| 53 | + MoveDirection straightRight = new MoveDirection(-1, 0, false); | |
| 54 | + MoveDirection straightLeft = new MoveDirection(1, 0, false); | |
| 55 | + | |
| 56 | + MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び | |
| 57 | + MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び | |
| 35 | 58 | } |
| 36 | 59 | } |
| @@ -5,40 +5,81 @@ | ||
| 5 | 5 | |
| 6 | 6 | namespace QuantumShogi.Logic |
| 7 | 7 | { |
| 8 | - class DirectionsGenerator | |
| 8 | + public class DirectionsGenerator | |
| 9 | 9 | { |
| 10 | - MoveDirectionsType[] moveDirections; | |
| 10 | + /// <summary> | |
| 11 | + /// 特定の駒に対する移動方向 | |
| 12 | + /// </summary> | |
| 13 | + MoveDirectionsType[] MoveDirectionsOfPice; | |
| 11 | 14 | |
| 15 | + /// <summary> | |
| 16 | + /// 全移動方向の配列 | |
| 17 | + /// </summary> | |
| 18 | + public MoveDirection[] moveDirectionsList { get; } | |
| 19 | + | |
| 20 | + /// <summary> | |
| 21 | + /// ある量子駒が動ける | |
| 22 | + /// </summary> | |
| 23 | + /// <param name="piece"></param> | |
| 24 | + /// <returns></returns> | |
| 25 | + public IEnumerable<MoveDirection> GetPieceOfMoveDirection(Piece piece) | |
| 26 | + { | |
| 27 | + List<MoveDirection> list = new List<MoveDirection>(); | |
| 28 | + for(int i = Piece.MIN; i < Piece.CountOfType; i++) | |
| 29 | + { | |
| 30 | + if (piece.IsTypeOf(i)) | |
| 31 | + { | |
| 32 | + list.AddRange( | |
| 33 | + MoveDirectionsOfPice[i].GetValues(piece.IsPromoted) | |
| 34 | + ); | |
| 35 | + } | |
| 36 | + } | |
| 37 | + return list.Distinct(); | |
| 38 | + } | |
| 39 | + | |
| 40 | + //一歩動く方向 | |
| 41 | + MoveDirection upper = new MoveDirection(0, -1, false);//前進 | |
| 42 | + MoveDirection upperLeft = new MoveDirection(1, -1, false);//左上 | |
| 43 | + MoveDirection upperRight = new MoveDirection(-1, -1, true);//右上 | |
| 44 | + MoveDirection down = new MoveDirection(0, 1, false);//下がる | |
| 45 | + MoveDirection downLeft = new MoveDirection(1, 1, false); | |
| 46 | + MoveDirection downRight = new MoveDirection(-1, 1, false); | |
| 47 | + MoveDirection right = new MoveDirection(-1, 0, false); | |
| 48 | + MoveDirection left = new MoveDirection(1, 0, false); | |
| 49 | + | |
| 50 | + //飛びききにはすぐ1歩動く方向は含めない。 | |
| 51 | + //例えば香車は直進すると定義されるが、直進+一歩前進と重複して定義する。 | |
| 52 | + MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進 | |
| 53 | + MoveDirection straightUpperLeft = new MoveDirection(1, -1, false); | |
| 54 | + MoveDirection straightUpperRight = new MoveDirection(-1, -1, true); | |
| 55 | + MoveDirection straightDown = new MoveDirection(0, 1, false); | |
| 56 | + MoveDirection straightDownLeft = new MoveDirection(1, 1, false); | |
| 57 | + MoveDirection straightDownRight = new MoveDirection(-1, 1, false); | |
| 58 | + MoveDirection straightRight = new MoveDirection(-1, 0, false); | |
| 59 | + MoveDirection straightLeft = new MoveDirection(1, 0, false); | |
| 60 | + | |
| 61 | + MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び | |
| 62 | + MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び | |
| 63 | + | |
| 12 | 64 | public DirectionsGenerator() |
| 13 | 65 | { |
| 14 | - //一歩動くきき | |
| 15 | - MoveDirection upper = new MoveDirection(0, -1, false);//前進 | |
| 16 | - MoveDirection upperLeft = new MoveDirection(1,-1,false);//左上 | |
| 17 | - MoveDirection upperRight = new MoveDirection(-1,-1,true);//右上 | |
| 18 | - MoveDirection down = new MoveDirection(0,1,false);//下がる | |
| 19 | - MoveDirection downLeft = new MoveDirection(1,1,false); | |
| 20 | - MoveDirection downRight = new MoveDirection(-1,1, false); | |
| 21 | - MoveDirection right = new MoveDirection(-1,0, false); | |
| 22 | - MoveDirection left = new MoveDirection(1,0, false); | |
| 23 | 66 | |
| 24 | - //飛びききにはすぐ一つとなりのききは含めない。 | |
| 25 | - //例えば香車は直進すると定義されるが、直進+一歩前進ができると定義する。 | |
| 26 | - MoveDirection straightUpper = new MoveDirection(0, -1, true);//前へ直進 | |
| 27 | - MoveDirection straightUpperLeft = new MoveDirection(1, -1, false); | |
| 28 | - MoveDirection straightUpperRight = new MoveDirection(-1, -1, true); | |
| 29 | - MoveDirection straightDown = new MoveDirection(0, 1, false); | |
| 30 | - MoveDirection straightDownLeft = new MoveDirection(1, 1, false); | |
| 31 | - MoveDirection straightDownRight = new MoveDirection(-1, 1, false); | |
| 32 | - MoveDirection straightRight = new MoveDirection(-1, 0, false); | |
| 33 | - MoveDirection straightLeft = new MoveDirection(1, 0, false); | |
| 67 | + moveDirectionsList = new MoveDirection[] | |
| 68 | + { | |
| 69 | + upper, upperLeft, upperRight, | |
| 70 | + left ,right, | |
| 71 | + down, downLeft, downRight , | |
| 72 | + straightUpper, straightUpperLeft, straightUpperRight, | |
| 73 | + straightLeft,straightRight, | |
| 74 | + straightDown, straightDownLeft, straightDownRight, | |
| 75 | + upper2Left, | |
| 76 | + upper2Right | |
| 77 | + }; | |
| 34 | 78 | |
| 35 | - MoveDirection upper2Left = new MoveDirection(1, -2, false);//桂馬飛び | |
| 36 | - MoveDirection upper2Right = new MoveDirection(-1, -2, true);//桂馬飛び | |
| 79 | + MoveDirectionsOfPice = new MoveDirectionsType[Piece.CountOfType]; | |
| 37 | 80 | |
| 38 | - moveDirections = new MoveDirectionsType[Piece.CountOfType()]; | |
| 39 | - | |
| 40 | 81 | //歩の移動方向 |
| 41 | - moveDirections[Piece.Pawn] = new MoveDirectionsType( | |
| 82 | + MoveDirectionsOfPice[Piece.Pawn] = new MoveDirectionsType( | |
| 42 | 83 | upper |
| 43 | 84 | ).AppendPromotedMove( |
| 44 | 85 | //との移動方向 |
| @@ -47,7 +88,7 @@ | ||
| 47 | 88 | down |
| 48 | 89 | ); |
| 49 | 90 | //香車の移動方向 |
| 50 | - moveDirections[Piece.Lance] = new MoveDirectionsType( | |
| 91 | + MoveDirectionsOfPice[Piece.Lance] = new MoveDirectionsType( | |
| 51 | 92 | upper, |
| 52 | 93 | straightUpper |
| 53 | 94 | ).AppendPromotedMove( |
| @@ -57,7 +98,7 @@ | ||
| 57 | 98 | down |
| 58 | 99 | ); |
| 59 | 100 | //桂馬の移動方向 |
| 60 | - moveDirections[Piece.Knight] = new MoveDirectionsType( | |
| 101 | + MoveDirectionsOfPice[Piece.Knight] = new MoveDirectionsType( | |
| 61 | 102 | upper2Left, upper2Right |
| 62 | 103 | ).AppendPromotedMove( |
| 63 | 104 | //圭の移動方向 |
| @@ -66,7 +107,7 @@ | ||
| 66 | 107 | down |
| 67 | 108 | ); |
| 68 | 109 | //銀の移動方向 |
| 69 | - moveDirections[Piece.Silver] = new MoveDirectionsType( | |
| 110 | + MoveDirectionsOfPice[Piece.Silver] = new MoveDirectionsType( | |
| 70 | 111 | upperLeft, upper, upperRight, |
| 71 | 112 | downLeft, downRight |
| 72 | 113 | ).AppendPromotedMove( |
| @@ -76,13 +117,13 @@ | ||
| 76 | 117 | down |
| 77 | 118 | ); |
| 78 | 119 | //金の移動方向 |
| 79 | - moveDirections[Piece.Gold] = new MoveDirectionsType( | |
| 120 | + MoveDirectionsOfPice[Piece.Gold] = new MoveDirectionsType( | |
| 80 | 121 | upperLeft,upper,upperRight, |
| 81 | 122 | left,right, |
| 82 | 123 | down |
| 83 | 124 | ); |
| 84 | 125 | //角の移動方向 |
| 85 | - moveDirections[Piece.Bishop] = new MoveDirectionsType( | |
| 126 | + MoveDirectionsOfPice[Piece.Bishop] = new MoveDirectionsType( | |
| 86 | 127 | upperLeft,upperRight, |
| 87 | 128 | downLeft,downRight, |
| 88 | 129 | straightUpperLeft,straightUpperRight, |
| @@ -96,7 +137,7 @@ | ||
| 96 | 137 | straightDownLeft, straightDownRight |
| 97 | 138 | ); |
| 98 | 139 | //飛車の移動方向 |
| 99 | - moveDirections[Piece.Rook] = new MoveDirectionsType( | |
| 140 | + MoveDirectionsOfPice[Piece.Rook] = new MoveDirectionsType( | |
| 100 | 141 | straightUpper, |
| 101 | 142 | straightLeft,straightRight, |
| 102 | 143 | straightDown |
| @@ -110,7 +151,7 @@ | ||
| 110 | 151 | straightDown |
| 111 | 152 | ); |
| 112 | 153 | //玉の移動方向 |
| 113 | - moveDirections[Piece.King] = new MoveDirectionsType( | |
| 154 | + MoveDirectionsOfPice[Piece.King] = new MoveDirectionsType( | |
| 114 | 155 | upperLeft,upper,upperRight, |
| 115 | 156 | left,right, |
| 116 | 157 | downLeft,down,downRight |
| @@ -17,8 +17,20 @@ | ||
| 17 | 17 | /// <summary> |
| 18 | 18 | /// 先手から見た駒の移動方向成り駒のとき |
| 19 | 19 | /// </summary> |
| 20 | - MoveDirection[] promotedMoveDirections = new MoveDirection[] { };//金、玉は0個の配列 | |
| 20 | + MoveDirection[] promotedMoveDirections = null; | |
| 21 | 21 | |
| 22 | + /// <summary> | |
| 23 | + /// 駒はなることが可能か | |
| 24 | + /// 金、玉はfalse | |
| 25 | + /// </summary> | |
| 26 | + public bool CanPromoted | |
| 27 | + { | |
| 28 | + get | |
| 29 | + { | |
| 30 | + return promotedMoveDirections != null; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 22 | 34 | public MoveDirection[] GetValues(bool promoted) |
| 23 | 35 | { |
| 24 | 36 | if (promoted) |