• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqt誰得windowscocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

練習用です。いろんなものがごちゃまぜです。


Commit MetaInfo

Revisionc74e1151aa94a5859863828fa74d677afc77b220 (tree)
Time2017-04-08 16:06:15
Author渡邉 喜光 <tccwas@gmai...>
Commiter渡邉 喜光

Log Message

オセロの初期化

Change Summary

Incremental Difference

--- a/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.cpp
+++ b/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.cpp
@@ -3,10 +3,36 @@
33
44 #include "stdafx.h"
55 #include "../Reversi2/Board.h"
6+#include <iostream>
7+using namespace std;
68
9+void output(Board &board) {
10+ for (int y = 0; y < ROW_MEM_SIZE; y++) {
11+ for (int x = 0; x < COL_MEM_SIZE; x++) {
12+ int c = board.Cells(x, y);
13+ if (c == BLACK) {
14+ cout << "●";
15+ }
16+ else if (c == WHITE) {
17+ cout << "〇";
18+ }
19+ else if (c == EMPTY) {
20+ cout << "・";
21+ }
22+ else if (c == WALL) {
23+ cout << "■";
24+ }
25+ else {
26+ cout << "×";
27+ }
28+ }
29+ cout << endl;
30+ }
31+}
732 int main()
833 {
934 Board b;
35+ output(b);
1036 return 0;
1137 }
1238
--- a/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.vcxproj
+++ b/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.vcxproj
@@ -143,6 +143,7 @@
143143 </ItemGroup>
144144 <ItemGroup>
145145 <ClCompile Include="..\Reversi2\Board.cpp" />
146+ <ClCompile Include="..\Reversi2\Move.cpp" />
146147 <ClCompile Include="ConsoleApplication1.cpp" />
147148 <ClCompile Include="stdafx.cpp">
148149 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
--- a/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.vcxproj.filters
+++ b/Reversi/Reversi2/ConsoleApplication1/ConsoleApplication1.vcxproj.filters
@@ -35,5 +35,8 @@
3535 <ClCompile Include="..\Reversi2\Board.cpp">
3636 <Filter>ソース ファイル</Filter>
3737 </ClCompile>
38+ <ClCompile Include="..\Reversi2\Move.cpp">
39+ <Filter>ソース ファイル</Filter>
40+ </ClCompile>
3841 </ItemGroup>
3942 </Project>
\ No newline at end of file
--- a/Reversi/Reversi2/Reversi2/Board.cpp
+++ b/Reversi/Reversi2/Reversi2/Board.cpp
@@ -2,8 +2,51 @@
22 #include "Board.h"
33
44
5+void Board::Do(Move *move)
6+{
7+ moves.push_back(*move);
8+}
9+
10+void Board::Undo()
11+{
12+ moves.pop_back();
13+}
14+
515 Board::Board()
616 {
17+ //四方を壁にする。
18+ const int x_of_left = 0;
19+ const int x_of_right = COL_MEM_SIZE - 1;
20+ const int y_of_top = 0;
21+ const int y_of_bottom = (ROW_MEM_SIZE - 1) * COL_MEM_SIZE;
22+
23+ for (int y = 0; y < CELLS_COUNT; y += COL_MEM_SIZE) {
24+ cells[x_of_left + y] = WALL;
25+ cells[x_of_right + y] = WALL;
26+ }
27+ for (int x = 1; x <= COL_SIZE; x++) {
28+ cells[x + y_of_top] = WALL;
29+ cells[x + y_of_bottom] = WALL;
30+ }
31+
32+
33+ //なにもおいてない状態にする。
34+ for (int y = COL_MEM_SIZE; y < CELLS_COUNT - COL_MEM_SIZE; y+= COL_MEM_SIZE) {
35+ for (int x = 1; x <= COL_SIZE; x++) {
36+ cells[x + y] = EMPTY;
37+ }
38+ }
39+
40+ //4つの石を初期配置する。
41+ cells[position(4, 4)] = WHITE;
42+ cells[position(5, 5)] = WHITE;
43+ cells[position(4, 5)] = BLACK;
44+ cells[position(5, 4)] = BLACK;
45+
46+ //初手にする。
47+ turn_count = 0;
48+
49+
750 }
851
952
--- a/Reversi/Reversi2/Reversi2/Board.h
+++ b/Reversi/Reversi2/Reversi2/Board.h
@@ -1,7 +1,85 @@
11 #pragma once
2+#include "Move.h"
3+#include <vector>
4+
5+/// <summary>
6+/// 盤の横の大きさ
7+/// </summary>
8+const int COL_SIZE = 8;
9+
10+/// <summary>
11+/// 盤の縦の大きさ
12+/// </summary>
13+const int ROW_SIZE = 8;
14+
15+/// <summary>
16+/// The col memory size
17+/// </summary>
18+const int COL_MEM_SIZE = 1 + COL_SIZE + 1;
19+
20+/// <summary>
21+/// The row memory size
22+/// </summary>
23+const int ROW_MEM_SIZE = 1 + ROW_SIZE + 1;
24+
25+
26+const int BLACK = 1;
27+const int WHITE = -1;
28+const int EMPTY = 0;
29+const int WALL = 2;
30+
231 class Board
332 {
33+ /// <summary>
34+ /// The cells count
35+ /// </summary>
36+ const int CELLS_COUNT = COL_MEM_SIZE * ROW_MEM_SIZE;
37+
38+
39+
40+ int cells[(ROW_SIZE + 2) * (COL_SIZE + 2)];
41+ int turn_count;
42+ int color_of_turn;
43+ std::vector<Move> moves;
44+
445 public:
46+ /// <summary>
47+ /// Positions the specified x and y.
48+ /// </summary>
49+ /// <param name="x">The x.</param>
50+ /// <param name="y">The y.</param>
51+ /// <returns></returns>
52+ int position(int x, int y) {
53+ return x + y * COL_MEM_SIZE;
54+ }
55+
56+ /// <summary>
57+ /// 位置変数の横成分
58+ /// </summary>
59+ /// <param name="position">The position.</param>
60+ /// <returns></returns>
61+ int x_of(int position) {
62+ return position % COL_MEM_SIZE;
63+ }
64+
65+ /// <summary>
66+ /// 位置変数の縦成分
67+ /// </summary>
68+ /// <param name="position">The position.</param>
69+ /// <returns></returns>
70+ int y_of(int position) {
71+ return position / COL_MEM_SIZE;
72+ }
73+
74+ int Cells(int x, int y) {
75+ int pos = position(x, y);
76+ return cells[pos];
77+ }
78+
79+ void Do(Move *move);
80+
81+ void Undo();
82+
583 Board();
684 ~Board();
785 };
--- /dev/null
+++ b/Reversi/Reversi2/Reversi2/Move.cpp
@@ -0,0 +1,12 @@
1+#include "stdafx.h"
2+#include "Move.h"
3+
4+
5+Move::Move()
6+{
7+}
8+
9+
10+Move::~Move()
11+{
12+}
--- /dev/null
+++ b/Reversi/Reversi2/Reversi2/Move.h
@@ -0,0 +1,33 @@
1+#pragma once
2+
3+
4+
5+/// <summary>
6+/// 差し手
7+/// </summary>
8+class Move
9+{
10+
11+ /// <summary>
12+ /// The drop down position
13+ /// 石を置いた場所
14+ /// </summary>
15+ int drop_pos;
16+ /// <summary>
17+ /// The reverse positions
18+ /// ひっくり返る位置
19+ /// 最大で18個ひっくり返る可能性がある。
20+ /// それは角に置いたときで3方向×6個 = 18個
21+ /// </summary>
22+ int rev_pos[18];
23+ int rev_pos_count;
24+public:
25+
26+ void AddRevpos(int position) {
27+ rev_pos[rev_pos_count] = position;
28+ rev_pos_count++;
29+ }
30+ Move();
31+ ~Move();
32+};
33+
--- a/Reversi/Reversi2/Reversi2/Reversi2.vcxproj
+++ b/Reversi/Reversi2/Reversi2/Reversi2.vcxproj
@@ -139,6 +139,7 @@
139139 </ItemGroup>
140140 <ItemGroup>
141141 <ClInclude Include="Board.h" />
142+ <ClInclude Include="Move.h" />
142143 <ClInclude Include="Resource.h" />
143144 <ClInclude Include="Reversi2.h" />
144145 <ClInclude Include="stdafx.h" />
@@ -146,6 +147,7 @@
146147 </ItemGroup>
147148 <ItemGroup>
148149 <ClCompile Include="Board.cpp" />
150+ <ClCompile Include="Move.cpp" />
149151 <ClCompile Include="Reversi2.cpp" />
150152 <ClCompile Include="stdafx.cpp">
151153 <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
--- a/Reversi/Reversi2/Reversi2/Reversi2.vcxproj.filters
+++ b/Reversi/Reversi2/Reversi2/Reversi2.vcxproj.filters
@@ -33,6 +33,9 @@
3333 <ClInclude Include="Board.h">
3434 <Filter>ヘッダー ファイル</Filter>
3535 </ClInclude>
36+ <ClInclude Include="Move.h">
37+ <Filter>ヘッダー ファイル</Filter>
38+ </ClInclude>
3639 </ItemGroup>
3740 <ItemGroup>
3841 <ClCompile Include="stdafx.cpp">
@@ -44,6 +47,9 @@
4447 <ClCompile Include="Board.cpp">
4548 <Filter>ソース ファイル</Filter>
4649 </ClCompile>
50+ <ClCompile Include="Move.cpp">
51+ <Filter>ソース ファイル</Filter>
52+ </ClCompile>
4753 </ItemGroup>
4854 <ItemGroup>
4955 <ResourceCompile Include="Reversi2.rc">