I am currently working on a tic tac toe multiplayer game built in Node.js.
My main issue is figuring out how to check for a win condition. I know how it works using an array but I want to program my game this way....
var mongoose = require('mongoose');
var gameSchema = new mongoose.Schema({
player1: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
player2: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
// This would be an array of selected spaces for 'x' or 'o'
placements: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Placement"
}],
// This would be the username of the current player.
currentPlayer: String
});
module.export = mongoose.model('Game', gameSchema);
Placement Schema:
var mongoose = require('mongoose');
var placementSchema = new mongoose.Schema({
marker: String, //x or o
selectedSpace: Number // 0-8
});
module.export = mongoose.model('Placement', placementSchema);
I want to use placements as an array of model Objects....
What would be the best way to check for a win condition this way?
Or should I rethink the way this model is setup?