removed the turns debug info and done some more logic
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ client/node_modules/
|
||||
server/node_modules/
|
||||
*.log
|
||||
*.env
|
||||
.turns-debug.json
|
||||
|
||||
@@ -271,7 +271,8 @@ function netSkipTurn()
|
||||
|
||||
function onTurnError(socket, args)
|
||||
{
|
||||
console.log(args);
|
||||
console.log('error', args);
|
||||
alert('Error in your turn: ' + args.error);
|
||||
}
|
||||
|
||||
function onturnProcessed(socket, args)
|
||||
|
||||
@@ -263,13 +263,33 @@ function PlayTurn(gameuid, playeruid, turn)
|
||||
const game = ActiveGames[gameuid];
|
||||
const turninfo = gameNextTurn(gameuid);
|
||||
|
||||
turn.turn = turninfo.newTurn;
|
||||
turn.oldboardtiles = ActiveGames[gameuid].gamestates[ActiveGames[gameuid].gamestates.length - 1].boardtiles;
|
||||
|
||||
// generate diff between oldboardtiles and newboardtiles
|
||||
const diff = turnDiff(turn.oldboardtiles, turn.boardtiles);
|
||||
if (diff.length === 0)
|
||||
{
|
||||
const error = {
|
||||
error: 'error-game-no-change'
|
||||
};
|
||||
return [error, undefined, undefined, undefined]
|
||||
}
|
||||
|
||||
// process outcome
|
||||
|
||||
// check if user is allowed to make that move
|
||||
|
||||
// process turn and allocate scores
|
||||
|
||||
// give user new tiles
|
||||
|
||||
turn.boardtiles = turn.oldboardtiles.append(turn.boardtiles);
|
||||
ActiveGames[gameuid].gamestates.push(turn);
|
||||
ActiveGames[gameuid].turn = turninfo.newTurn;
|
||||
ActiveGames[gameuid].turn = turninfo.newTotalTurn;
|
||||
ActiveGames[gameuid].turntotal = turninfo.newTotalTurn;
|
||||
|
||||
// give user new tiles
|
||||
|
||||
return [turn, turninfo];
|
||||
return [undefined, turn, turninfo, {}];
|
||||
}
|
||||
|
||||
function SkipTurn(gameuid, playeruid)
|
||||
@@ -287,7 +307,7 @@ function SkipTurn(gameuid, playeruid)
|
||||
|
||||
ActiveGames[gameuid].gamestates.push(turn);
|
||||
ActiveGames[gameuid].turn = turninfo.newTurn;
|
||||
ActiveGames[gameuid].turn = turninfo.newTotalTurn;
|
||||
ActiveGames[gameuid].turntotal = turninfo.newTotalTurn;
|
||||
|
||||
return [turn, turninfo];
|
||||
}
|
||||
@@ -298,6 +318,7 @@ function gameNextTurn(gameuid)
|
||||
let newTurn = ActiveGames[gameuid].turn += 1;
|
||||
newTurn = ActiveGames[gameuid].turn % playerCount;
|
||||
const newTotalTurn = ActiveGames[gameuid].turntotal += 1;
|
||||
|
||||
return {
|
||||
turnplayer: ActiveGames[gameuid].players[newTurn],
|
||||
newTurn: newTurn,
|
||||
@@ -305,17 +326,6 @@ function gameNextTurn(gameuid)
|
||||
};
|
||||
}
|
||||
|
||||
// returns tuple ([newtileset], [newusertiles])
|
||||
function ExchangeTiles(tileset, tilesToExchange)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function UserLeaveGame(useruid)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// same as how the
|
||||
function EndGame()
|
||||
{
|
||||
@@ -323,6 +333,27 @@ function EndGame()
|
||||
}
|
||||
|
||||
|
||||
// verrryyy naive way of doing it but it returns the difference in tiles between args
|
||||
function turnDiff(turntilesold, turntilesnew)
|
||||
{
|
||||
let ret = [];
|
||||
if (turntilesold.length === 0) return turntilesnew;
|
||||
if (turntilesnew.length === 0) return []; // because there's no new tiles ennit
|
||||
for (const tile1 of turntilesold)
|
||||
{
|
||||
for (const tile2 of turntilesnew)
|
||||
{
|
||||
if (JSON.stringify(tile1) === JSON.stringify(tile2))
|
||||
continue;
|
||||
if (ret.includes(tile2) || ret.includes(tile1))
|
||||
continue;
|
||||
ret.push(tile2);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
// Game validation exports
|
||||
|
||||
|
||||
@@ -420,9 +420,14 @@ function GamePlayTurn(socket, args)
|
||||
} else
|
||||
{
|
||||
// TODO: validate args
|
||||
const [outcome, turninfo] = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||
const [err, outcome, turninfo, newuserpieces] = Game.Logic.PlayTurn(game.uid, user.uid, args)
|
||||
|
||||
// process errorsq
|
||||
// process errors
|
||||
if (err)
|
||||
{
|
||||
socket.emit('game-turn-error', err);
|
||||
return;
|
||||
}
|
||||
|
||||
io.to(game.uid).emit('game-turn-processed', {
|
||||
outcome: outcome
|
||||
|
||||
403
turns-debug.json
403
turns-debug.json
@@ -1,403 +0,0 @@
|
||||
{
|
||||
"uid": "UQWPWN",
|
||||
"locale": "en",
|
||||
"players": [
|
||||
{
|
||||
"uid": "4034e8f531d4ad69",
|
||||
"name": "ben",
|
||||
"activetiles": [
|
||||
"E",
|
||||
"R",
|
||||
"I",
|
||||
"F",
|
||||
"I",
|
||||
"E",
|
||||
"U"
|
||||
],
|
||||
"score": 0
|
||||
}
|
||||
],
|
||||
"turn": 1,
|
||||
"turntotal": 1,
|
||||
"gamestates": [
|
||||
{
|
||||
"playeruid": -1,
|
||||
"turn": 0,
|
||||
"turntype": "",
|
||||
"outcome": {
|
||||
"valid": false
|
||||
},
|
||||
"oldboardtiles": [],
|
||||
"boardtiles": []
|
||||
},
|
||||
{
|
||||
"playeruid": "4034e8f531d4ad69",
|
||||
"turn": -1,
|
||||
"turntype": "PLACE",
|
||||
"outcome": {},
|
||||
"oldboardtiles": [],
|
||||
"boardtiles": [
|
||||
{
|
||||
"pos": {
|
||||
"x": 5,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "NONE",
|
||||
"letter": "I",
|
||||
"score": -1
|
||||
},
|
||||
{
|
||||
"pos": {
|
||||
"x": 6,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "NONE",
|
||||
"letter": "F",
|
||||
"score": -1
|
||||
},
|
||||
{
|
||||
"pos": {
|
||||
"x": 7,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "TW",
|
||||
"letter": "I",
|
||||
"score": -1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"tilebag": [
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"L",
|
||||
"L",
|
||||
"L",
|
||||
"L",
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
"U",
|
||||
"U",
|
||||
"U",
|
||||
"D",
|
||||
"D",
|
||||
"D",
|
||||
"D",
|
||||
"G",
|
||||
"G",
|
||||
"G",
|
||||
"B",
|
||||
"B",
|
||||
"C",
|
||||
"C",
|
||||
"M",
|
||||
"M",
|
||||
"P",
|
||||
"P",
|
||||
"F",
|
||||
"H",
|
||||
"H",
|
||||
"V",
|
||||
"V",
|
||||
"W",
|
||||
"W",
|
||||
"Y",
|
||||
"Y",
|
||||
"K",
|
||||
"J",
|
||||
"X",
|
||||
"Q",
|
||||
"Z",
|
||||
"_",
|
||||
"_"
|
||||
],
|
||||
"tileset": [
|
||||
"A",
|
||||
"B",
|
||||
"C",
|
||||
"D",
|
||||
"E",
|
||||
"F",
|
||||
"G",
|
||||
"H",
|
||||
"I",
|
||||
"J",
|
||||
"K",
|
||||
"L",
|
||||
"M",
|
||||
"N",
|
||||
"O",
|
||||
"P",
|
||||
"Q",
|
||||
"R",
|
||||
"S",
|
||||
"T",
|
||||
"U",
|
||||
"V",
|
||||
"W",
|
||||
"X",
|
||||
"Y",
|
||||
"Z"
|
||||
]
|
||||
}{
|
||||
"uid": "UQWPWN",
|
||||
"locale": "en",
|
||||
"players": [
|
||||
{
|
||||
"uid": "4034e8f531d4ad69",
|
||||
"name": "ben",
|
||||
"activetiles": [
|
||||
"E",
|
||||
"R",
|
||||
"I",
|
||||
"F",
|
||||
"I",
|
||||
"E",
|
||||
"U"
|
||||
],
|
||||
"score": 0
|
||||
}
|
||||
],
|
||||
"turn": 2,
|
||||
"turntotal": 2,
|
||||
"gamestates": [
|
||||
{
|
||||
"playeruid": -1,
|
||||
"turn": 0,
|
||||
"turntype": "",
|
||||
"outcome": {
|
||||
"valid": false
|
||||
},
|
||||
"oldboardtiles": [],
|
||||
"boardtiles": []
|
||||
},
|
||||
{
|
||||
"playeruid": "4034e8f531d4ad69",
|
||||
"turn": -1,
|
||||
"turntype": "PLACE",
|
||||
"outcome": {},
|
||||
"oldboardtiles": [],
|
||||
"boardtiles": [
|
||||
{
|
||||
"pos": {
|
||||
"x": 5,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "NONE",
|
||||
"letter": "I",
|
||||
"score": -1
|
||||
},
|
||||
{
|
||||
"pos": {
|
||||
"x": 6,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "NONE",
|
||||
"letter": "F",
|
||||
"score": -1
|
||||
},
|
||||
{
|
||||
"pos": {
|
||||
"x": 7,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "TW",
|
||||
"letter": "I",
|
||||
"score": -1
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"playeruid": "4034e8f531d4ad69",
|
||||
"turn": -1,
|
||||
"turntype": "PLACE",
|
||||
"outcome": {},
|
||||
"oldboardtiles": [],
|
||||
"boardtiles": [
|
||||
{
|
||||
"pos": {
|
||||
"x": 8,
|
||||
"y": 14
|
||||
},
|
||||
"modifier": "NONE",
|
||||
"letter": "U",
|
||||
"score": -1
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"tilebag": [
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"E",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"A",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"I",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"O",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"N",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"R",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"T",
|
||||
"L",
|
||||
"L",
|
||||
"L",
|
||||
"L",
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
"S",
|
||||
"U",
|
||||
"U",
|
||||
"U",
|
||||
"D",
|
||||
"D",
|
||||
"D",
|
||||
"D",
|
||||
"G",
|
||||
"G",
|
||||
"G",
|
||||
"B",
|
||||
"B",
|
||||
"C",
|
||||
"C",
|
||||
"M",
|
||||
"M",
|
||||
"P",
|
||||
"P",
|
||||
"F",
|
||||
"H",
|
||||
"H",
|
||||
"V",
|
||||
"V",
|
||||
"W",
|
||||
"W",
|
||||
"Y",
|
||||
"Y",
|
||||
"K",
|
||||
"J",
|
||||
"X",
|
||||
"Q",
|
||||
"Z",
|
||||
"_",
|
||||
"_"
|
||||
],
|
||||
"tileset": [
|
||||
"A",
|
||||
"B",
|
||||
"C",
|
||||
"D",
|
||||
"E",
|
||||
"F",
|
||||
"G",
|
||||
"H",
|
||||
"I",
|
||||
"J",
|
||||
"K",
|
||||
"L",
|
||||
"M",
|
||||
"N",
|
||||
"O",
|
||||
"P",
|
||||
"Q",
|
||||
"R",
|
||||
"S",
|
||||
"T",
|
||||
"U",
|
||||
"V",
|
||||
"W",
|
||||
"X",
|
||||
"Y",
|
||||
"Z"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user