| @@ -0,0 +1,27 @@ | ||
| 1 | +using Microsoft.VisualStudio.TestTools.UnitTesting; | |
| 2 | +using QuantumShogi.Logic; | |
| 3 | +using System; | |
| 4 | +using System.Collections.Generic; | |
| 5 | +using System.Linq; | |
| 6 | +using System.Text; | |
| 7 | + | |
| 8 | +namespace QuantumShogi.Logic.Tests | |
| 9 | +{ | |
| 10 | + [TestClass()] | |
| 11 | + public class BoardInitializerTests | |
| 12 | + { | |
| 13 | + [TestMethod()] | |
| 14 | + public void GetCellsTest() | |
| 15 | + { | |
| 16 | + var initialize = new BoardInitializer(); | |
| 17 | + var p11 = initialize.GetCells(1, 1); | |
| 18 | + Assert.IsTrue(p11.IsWhite); | |
| 19 | + var p37 = initialize.GetCells(3, 7); | |
| 20 | + Assert.IsTrue(p37.IsBlack); | |
| 21 | + var p00 = initialize.GetCells(0, 0); | |
| 22 | + Assert.IsTrue(p00.IsWall); | |
| 23 | + var p12 = initialize.GetCells(1, 2); | |
| 24 | + Assert.IsTrue(p12.IsEmtpy); | |
| 25 | + } | |
| 26 | + } | |
| 27 | +} | |
| \ No newline at end of file |
| @@ -0,0 +1,59 @@ | ||
| 1 | +using System; | |
| 2 | +using System.Collections.Generic; | |
| 3 | +using System.Linq; | |
| 4 | +using System.Text; | |
| 5 | + | |
| 6 | +namespace QuantumShogi.Logic | |
| 7 | +{ | |
| 8 | + | |
| 9 | + public class BoardInitializer | |
| 10 | + { | |
| 11 | + const int L = 9;//壁 | |
| 12 | + const int B = 1;//先手の量子駒 | |
| 13 | + const int W = 2;//後手の量子駒 | |
| 14 | + const int E = 0;//空 | |
| 15 | + int[][] initialArrangement = { | |
| 16 | + new int[] {L,L,L,L,L,L,L,L,L,L,L}, | |
| 17 | + new int[] {L,W,W,W,W,W,W,W,W,W,L}, | |
| 18 | + new int[] {L,E,W,E,E,E,E,E,W,E,L}, | |
| 19 | + new int[] {L,W,W,W,W,W,W,W,W,W,L}, | |
| 20 | + new int[] {L,E,E,E,E,E,E,E,E,E,L}, | |
| 21 | + new int[] {L,E,E,E,E,E,E,E,E,E,L}, | |
| 22 | + new int[] {L,E,E,E,E,E,E,E,E,E,L}, | |
| 23 | + new int[] {L,B,B,B,B,B,B,B,B,B,L}, | |
| 24 | + new int[] {L,E,B,E,E,E,E,E,B,E,L}, | |
| 25 | + new int[] {L,B,B,B,B,B,B,B,B,B,L}, | |
| 26 | + new int[] {L,L,L,L,L,L,L,L,L,L,L} | |
| 27 | + }; | |
| 28 | + public Piece GetCells(int x,int y) | |
| 29 | + { | |
| 30 | + int s = initialArrangement[y][10 - x]; | |
| 31 | + switch (s) | |
| 32 | + { | |
| 33 | + case L: | |
| 34 | + { | |
| 35 | + return Piece.GetWall(); | |
| 36 | + } | |
| 37 | + case B: | |
| 38 | + { | |
| 39 | + return Piece.GetInitBlack(); | |
| 40 | + } | |
| 41 | + case W: | |
| 42 | + { | |
| 43 | + return Piece.GetInitWhite(); | |
| 44 | + } | |
| 45 | + case E: | |
| 46 | + { | |
| 47 | + return Piece.GetEmpty(); | |
| 48 | + } | |
| 49 | + default: | |
| 50 | + { | |
| 51 | + System.Diagnostics.Debug.Assert(false); | |
| 52 | + break; | |
| 53 | + } | |
| 54 | + } | |
| 55 | + return Piece.GetEmpty(); | |
| 56 | + | |
| 57 | + } | |
| 58 | + } | |
| 59 | +} |
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | namespace QuantumShogi.Logic |
| 7 | 7 | { |
| 8 | - class Piece | |
| 8 | + public class Piece | |
| 9 | 9 | { |
| 10 | 10 | private bool[] _isTypeOf = new bool[CountOfType()]; |
| 11 | 11 | /// <summary> |
| @@ -67,7 +67,7 @@ | ||
| 67 | 67 | /// 先手の初期量子駒 |
| 68 | 68 | /// </summary> |
| 69 | 69 | /// <returns></returns> |
| 70 | - public Piece GetInitBlack() | |
| 70 | + public static Piece GetInitBlack() | |
| 71 | 71 | { |
| 72 | 72 | return new Piece(true,false,true); |
| 73 | 73 | } |
| @@ -75,7 +75,7 @@ | ||
| 75 | 75 | /// 後手の初期量子駒 |
| 76 | 76 | /// </summary> |
| 77 | 77 | /// <returns></returns> |
| 78 | - public Piece GetInitWhite() | |
| 78 | + public static Piece GetInitWhite() | |
| 79 | 79 | { |
| 80 | 80 | return new Piece(false, true, true); |
| 81 | 81 | } |
| @@ -86,7 +86,7 @@ | ||
| 86 | 86 | } |
| 87 | 87 | static private Piece empty = CreateEmpty(); |
| 88 | 88 | |
| 89 | - public Piece GetEmpty() | |
| 89 | + public static Piece GetEmpty() | |
| 90 | 90 | { |
| 91 | 91 | return empty; |
| 92 | 92 | } |
| @@ -97,7 +97,7 @@ | ||
| 97 | 97 | |
| 98 | 98 | } |
| 99 | 99 | static private Piece wall = CreateWall(); |
| 100 | - public Piece GetWall() | |
| 100 | + public static Piece GetWall() | |
| 101 | 101 | { |
| 102 | 102 | return wall; |
| 103 | 103 | } |
| @@ -7,9 +7,34 @@ | ||
| 7 | 7 | { |
| 8 | 8 | class Move |
| 9 | 9 | { |
| 10 | + /// <summary> | |
| 11 | + /// 駒の移動元 | |
| 12 | + /// </summary> | |
| 10 | 13 | public int from { get; set; } |
| 14 | + /// <summary> | |
| 15 | + /// 駒の移動先 | |
| 16 | + /// </summary> | |
| 11 | 17 | public int to { get; set; } |
| 18 | + /// <summary> | |
| 19 | + /// 移動または打った駒 | |
| 20 | + /// </summary> | |
| 12 | 21 | public Piece piece { get; set; } |
| 13 | - public int | |
| 22 | + /// <summary> | |
| 23 | + /// 取られた駒 | |
| 24 | + /// </summary> | |
| 25 | + public Piece capture { get; set; } | |
| 26 | + /// <summary> | |
| 27 | + /// 駒がなったか | |
| 28 | + /// </summary> | |
| 29 | + public bool promote; | |
| 30 | + public Move(int from,int to,Piece piece,Piece capture = null,bool promote = false) | |
| 31 | + { | |
| 32 | + this.from = from; | |
| 33 | + this.to = to; | |
| 34 | + this.piece = piece; | |
| 35 | + this.capture = capture; | |
| 36 | + this.promote = promote; | |
| 37 | + | |
| 38 | + } | |
| 14 | 39 | } |
| 15 | 40 | } |
| @@ -7,37 +7,51 @@ | ||
| 7 | 7 | { |
| 8 | 8 | class Board |
| 9 | 9 | { |
| 10 | - const int SIZE_OF_X = 9 + 2; | |
| 11 | - const int SIZE_OF_Y = 9 + 2; | |
| 10 | + /// <summary> | |
| 11 | + /// 盤の横サイズ | |
| 12 | + /// </summary> | |
| 13 | + const int SIZE_OF_X = 9; | |
| 14 | + /// <summary> | |
| 15 | + /// 盤の縦サイズ | |
| 16 | + /// </summary> | |
| 17 | + const int SIZE_OF_Y = 9; | |
| 18 | + /// <summary> | |
| 19 | + /// 壁を含めた盤の横サイズ | |
| 20 | + /// </summary> | |
| 21 | + const int MEM_SIZE_OF_X = SIZE_OF_X + 2; | |
| 22 | + /// <summary> | |
| 23 | + /// 盤を含めた盤の縦サイズ | |
| 24 | + /// </summary> | |
| 25 | + const int MEM_SIZE_OF_Y = SIZE_OF_Y + 2; | |
| 26 | + | |
| 27 | + int GetIndexOfCell(int x, int y) | |
| 28 | + { | |
| 29 | + return MEM_SIZE_OF_X * y + x; | |
| 30 | + } | |
| 12 | 31 | private Piece[] _cells; |
| 13 | 32 | public Piece GetCells(int x,int y) |
| 14 | 33 | { |
| 15 | - return _cells[SIZE_OF_X * y + x]; | |
| 34 | + return _cells[GetIndexOfCell(x, y)]; | |
| 16 | 35 | } |
| 17 | 36 | private void SetCell(int x,int y,Piece koma) |
| 18 | 37 | { |
| 19 | - | |
| 38 | + _cells[GetIndexOfCell(x, y)] = koma; | |
| 20 | 39 | } |
| 21 | - public Board() | |
| 40 | + public Board(BoardInitializer boardInitializer) | |
| 22 | 41 | { |
| 23 | - _cells = new Piece[SIZE_OF_X * SIZE_OF_Y]; | |
| 42 | + _cells = new Piece[MEM_SIZE_OF_X * MEM_SIZE_OF_Y]; | |
| 43 | + for(int i = 0; i < _cells.Count(); i++) | |
| 44 | + { | |
| 45 | + _cells[i] = Piece.GetWall(); | |
| 46 | + } | |
| 47 | + for(int x = 1; x <= SIZE_OF_X; x++) | |
| 48 | + { | |
| 49 | + for(int y = 1; y <= SIZE_OF_Y; y++) | |
| 50 | + { | |
| 51 | + SetCell(x, y, boardInitializer.GetCells(x, y)); | |
| 52 | + } | |
| 53 | + } | |
| 24 | 54 | |
| 25 | - //9 壁 | |
| 26 | - //1 量子 | |
| 27 | - //0 空 | |
| 28 | - int[][] initialArrangement = { | |
| 29 | - new int[] {9,9,9,9,9,9,9,9,9,9,9}, | |
| 30 | - new int[] {9,1,1,1,1,1,1,1,1,1,9}, | |
| 31 | - new int[] {9,0,1,0,0,0,0,0,1,0,9}, | |
| 32 | - new int[] {9,1,1,1,1,1,1,1,1,1,9}, | |
| 33 | - new int[] {9,0,0,0,0,0,0,0,0,0,9}, | |
| 34 | - new int[] {9,0,0,0,0,0,0,0,0,0,9}, | |
| 35 | - new int[] {9,0,0,0,0,0,0,0,0,0,9}, | |
| 36 | - new int[] {9,1,1,1,1,1,1,1,1,1,9}, | |
| 37 | - new int[] {9,0,1,0,0,0,0,0,1,0,9}, | |
| 38 | - new int[] {9,1,1,1,1,1,1,1,1,1,9}, | |
| 39 | - new int[] {9,9,9,9,9,9,9,9,9,9,9} | |
| 40 | - }; | |
| 41 | 55 | } |
| 42 | 56 | |
| 43 | 57 | } |