Skip to content

Commit

Permalink
Rename PutResult -> Action
Browse files Browse the repository at this point in the history
  • Loading branch information
saroro1 committed Jul 14, 2022
1 parent a07a142 commit 3c7a999
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 34 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {Omok} = require("./src/Omok/OmokMain");
const {Occupied, InvalidPosition, PutError, Forbid33, Forbid44, Forbid6, Forbid, BlackWins, WhiteWins, PutComplete,} = require("./src/Omok/PutResult/putResult");
const {Occupied, InvalidPosition, PutError, Forbid33, Forbid44, Forbid6, Forbid, BlackWins, WhiteWins, PutComplete, Undo} = require("./src/Omok/ActionClass/Action");
module.exports = {
"Omok" : Omok,
"Occupied" : Occupied,
Expand All @@ -12,4 +12,5 @@ module.exports = {
"BlackWins" : BlackWins,
"WhiteWins" : WhiteWins,
"PutComplete" : PutComplete,
"Undo" : Undo,
}
17 changes: 17 additions & 0 deletions src/Omok/PutResult/putResult.js → src/Omok/ActionClass/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@
InvalidPosition.prototype.constructor = InvalidPosition;
Occupied.prototype = Object.create(PutError.prototype);
Occupied.prototype.constructor = Occupied;

function Undo(){
this.status = "UNDO";
this.code = -1;
this.currentTurn = "";
this.boardStack = boardStack;
this.period = 0;
this.rule = {
"ruleName" : "",
"rule" : {},
}

}
module.exports = {
PutComplete: PutComplete,
BlackWins : BlackWins,
Expand All @@ -119,8 +132,12 @@
PutError : PutError,
InvalidPosition : InvalidPosition,
Occupied : Occupied,
Undo : Undo,
}





})();

58 changes: 27 additions & 31 deletions src/Omok/OmokMain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Undo} from "./ActionClass/Action";

(function (){
const PutResult = require("./PutResult/putResult");
const PutResult = require("./ActionClass/Action");
const {Occupied, InvalidPosition, PutError, Forbid33, Forbid44, Forbid6, Forbid, BlackWins, WhiteWins, PutComplete,} = PutResult;
function Omok(){
const EMPTYSTONE = 0;
Expand All @@ -23,6 +24,7 @@

/**
* 보드 초기화 할때 사용
* @return void
*/
function resetBoard(){
turn = 1;
Expand Down Expand Up @@ -959,7 +961,7 @@
}
/**
* 좌표("H8")으로 돌 놓기
* @param cord
* @param {string} cord
* @return {InvalidPosition|Occupied|Forbid33|Forbid44|Forbid6|BlackWins|WhiteWins|PutComplete}
*/
function putStoneByCord(cord){
Expand Down Expand Up @@ -1110,13 +1112,13 @@
},
/**
* 돌을 배치합니다
* @param cord
* @param {string} cord
* @return {InvalidPosition|Occupied|Forbid33|Forbid44|Forbid6|BlackWins|WhiteWins|PutComplete}
*/
"putStone" : (cord)=> putStoneByCord(cord),
/**
* 해당 장소가 오목이 되는지 검사합니다
* @param cord
* @param {string} cord
* @return {boolean}
*/
"isFive" : (cord)=>{
Expand All @@ -1125,7 +1127,7 @@
},
/**
* 해당 장소가 장목(육목)이 되는지 검사합니다
* @param cord
* @param {string} cord
* @return {boolean}
*/
"isOverLine" : (cord)=>{
Expand All @@ -1134,7 +1136,7 @@
},
/**
* 해당 장소가 44가 되는지 확인합니다
* @param cord
* @param {string} cord
* @return {boolean}
*/
"isDoubleFour" : (cord)=>{
Expand All @@ -1143,7 +1145,7 @@
},
/**
* 해당 장소가 33이 되는지 확인합니다.
* @param cord
* @param {string} cord
* @return {boolean}
*/
"isDoubleThree" : (cord)=>{
Expand All @@ -1153,25 +1155,23 @@
},
/**
* 보드를 초기화합니다
* @return void
*/
"reset" : ()=>resetBoard(),

/**
* 되돌리기를 합니다.
* @return {{currentTurn: string, code: number, rule: {ruleName: string, rule: {allow44: boolean[], allow33: boolean[], sixWin: boolean[], allow6: boolean[]}}, turn: number, boardStack: *[], status: string}|{currentTurn: (string), code: number, rule: {ruleName: string, rule: {allow44: boolean[], allow33: boolean[], sixWin: boolean[], allow6: boolean[]}}, turn: number, boardStack: *[], status: string}}
* 되돌리기
* @return {Undo}
*/
"undo" : ()=>{
if(boardStack.length ===0 ){
return {
"status": "OK",
"code": -1,
"currentTurn": "b",
"boardStack": [],
"turn": 1,
"rule": {
"ruleName": ruleName,
"rule": rule,
}
}
const undo = new Undo();
undo.currentTurn = "b";
undo.boardStack = [];
undo.period = turn;
undo.rule.ruleName = ruleName;
undo.rule.rule = rule;
return undo;
}
else{
const last = boardStack.pop();
Expand All @@ -1180,17 +1180,13 @@
setStone(x,y,EMPTYSTONE);
isBlackTurn = !isBlackTurn;
turn --;
return {
"status": "UNDO",
"code": -1,
"currentTurn": isBlackTurn ? "b" : "w",
"boardStack": boardStack,
"turn": turn,
"rule": {
"ruleName": ruleName,
"rule": rule,
}
}
const undo = new Undo();
undo.currentTurn = isBlackTurn ? "b" : "w";
undo.boardStack = boardStack;
undo.period = turn;
undo.rule.ruleName = ruleName;
undo.rule.rule = rule;
return undo;
}
},
/**
Expand Down
4 changes: 2 additions & 2 deletions test/OmokTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ const expect = chai.expect;

const {Omok} = require("../src/Omok/OmokMain");
const assert = require("assert");
const {PutError, PutComplete, InvalidPosition, Occupied, BlackWins, Forbid, Forbid6, WhiteWins, Forbid33} = require("../src/Omok/PutResult/putResult");
const {PutError, PutComplete, InvalidPosition, Occupied, BlackWins, Forbid, Forbid6, WhiteWins, Forbid33} = require("../src/Omok/ActionClass/Action");
const game = new Omok();
describe("오목", function () {
it("착수 확인", function () {

game.reset();
assert.strictEqual( game.putStone("H122") instanceof InvalidPosition ,true)
assert.strictEqual( game.putStone("H8") instanceof PutComplete ,true)
Expand Down Expand Up @@ -114,7 +115,6 @@ describe("오목", function () {
game.putStone("I9");
game.putStone("G8");
game.putStone("J8");

game.putStone("J9");
game.putStone("H7");
game.putStone("G9");
Expand Down

0 comments on commit 3c7a999

Please sign in to comment.