diff --git a/lib/setFreekicks.js b/lib/setFreekicks.js index 002d161..2d6964d 100644 --- a/lib/setFreekicks.js +++ b/lib/setFreekicks.js @@ -1,8 +1,150 @@ const common = require(`../lib/common`) -const setPos = require(`../lib/setPositions`) + +function setTopFreekick(matchDetails) { + removeBallFromAllPlayers(matchDetails) + let { kickOffTeam, secondTeam } = matchDetails + let [pitchWidth, pitchHeight] = matchDetails.pitchSize + let [ballX, ballY] = matchDetails.ball.position + let attack = (kickOffTeam.players[0].originPOS[1] < pitchHeight / 2) ? kickOffTeam : secondTeam + let defence = (kickOffTeam.players[0].originPOS[1] < pitchHeight / 2) ? secondTeam : kickOffTeam + let hundredToHalfway = common.isBetween(ballY, 100, (pitchHeight / 2) + 1) + let halfwayToLastQuarter = common.isBetween(ballY, pitchHeight / 2, pitchHeight - (pitchHeight / 4)) + let penaltyXspan = common.isBetween(ballX, (pitchWidth / 4) + 5, (pitchWidth - (pitchWidth / 4) - 5)) + let leftOfPenaltyXspan = common.isBetween(ballX, 0, (pitchWidth / 4) + 5) + let rightOfPenaltyXspan = common.isBetween(ballX, (pitchWidth - (pitchWidth / 4) - 5), pitchWidth) + let upperFinalQuarter = common.isBetween(ballY, pitchHeight - (pitchHeight / 5), pitchHeight - (pitchHeight / 6) - 5) + let lowerFinalQuarter = common.isBetween(ballY, pitchHeight - (pitchHeight / 6) - 5, pitchHeight) + + if (ballY < 101) return setTopOneHundredYPos(matchDetails, attack, defence) + if (hundredToHalfway) return setTopOneHundredToHalfwayYPos(matchDetails, attack, defence) + if (halfwayToLastQuarter) return setTopHalfwayToBottomQuarterYPos(matchDetails, attack, defence) + if (penaltyXspan && upperFinalQuarter) return setTopBottomQuarterCentreYPos(matchDetails, attack, defence) + if (leftOfPenaltyXspan && upperFinalQuarter) return setTopUpperFinalQuarterLeftPos(matchDetails, attack, defence) + if (leftOfPenaltyXspan && lowerFinalQuarter) return setTopLowerFinalQuarterBylineLeftPos(matchDetails, attack, defence) + if (rightOfPenaltyXspan && upperFinalQuarter) return setTopUpperFinalQuarterRightPos(matchDetails, attack, defence) + if (rightOfPenaltyXspan && lowerFinalQuarter) return setTopLowerFinalQuarterBylineRightPos(matchDetails, attack, defence) +} + +function setBottomFreekick(matchDetails) { + return matchDetails +} + +function setTopOneHundredYPos(matchDetails, attack, defence) { + attack.players[0].hasBall = true + let { ball } = matchDetails + ball.Player = attack.players[0].name + ball.withTeam = attack.name + ball.direction = 'south' + for (let player of attack.players) { + if (player.position == 'GK') player.startPOS = matchDetails.ball.position.map(x => x) + if (player.position != 'GK') player.startPOS = player.originPOS.map(x => x) + } + for (let player of defence.players) { + if (player.position == 'GK') player.startPOS = player.originPOS.map(x => x) + if (player.position != 'GK') player.startPOS = [player.originPOS[0], player.originPOS[1] - 100] + } + return matchDetails +} + +function setTopOneHundredToHalfwayYPos(matchDetails, attack, defence) { + let { ball } = matchDetails + let [, pitchHeight] = matchDetails.pitchSize + let goalieToKick = common.isBetween(ball.position[1], 0, (pitchHeight * 0.25) + 1) + let kickPlayer = (goalieToKick) ? attack.players[0] : attack.players[3] + kickPlayer.hasBall = true + ball.Player = kickPlayer.name + ball.withTeam = attack.name + ball.direction = 'south' + for (let player of attack.players) { + if (kickPlayer.position == 'GK') { + if (player.position == 'GK') player.startPOS = ball.position.map(x => x) + if (player.name != kickPlayer.name) player.startPOS = [player.originPOS[0], player.originPOS[1] + 300] + } else { + let newYPOS = player.originPOS[1] + (ball.position[1] - player.originPOS[1]) + 300 + if (player.name == kickPlayer.name) player.startPOS = ball.position.map(x => x) + else if (player.position == 'GK') { + let maxYPOSCheck = parseInt(common.upToMax(newYPOS, pitchHeight * 0.25), 10) + player.startPOS = [player.originPOS[0], maxYPOSCheck] + } else if (['CB', 'LB', 'RB'].includes(player.position)) { + let maxYPOSCheck = parseInt(common.upToMax(newYPOS, pitchHeight * 0.5), 10) + player.startPOS = [player.originPOS[0], maxYPOSCheck] + } else if (['CM', 'LM', 'RM'].includes(player.position)) { + let maxYPOSCheck = parseInt(common.upToMax(newYPOS, pitchHeight * 0.75), 10) + player.startPOS = [player.originPOS[0], maxYPOSCheck] + } else { + let maxYPOSCheck = parseInt(common.upToMax(newYPOS, pitchHeight * 0.9), 10) + player.startPOS = [player.originPOS[0], maxYPOSCheck] + } + } + } + for (let player of defence.players) { + if (kickPlayer.position == 'GK') { + if (player.position == 'GK') player.startPOS = player.originPOS.map(x => x) + if (player.position != 'GK') player.startPOS = [player.originPOS[0], player.originPOS[1] - 100] + } else { + if (['GK', 'CB', 'LB', 'RB'].includes(player.position)) player.startPOS = player.originPOS.map(x => x) + else if (['CM', 'LM', 'RM'].includes(player.position)) { + player.startPOS = [player.originPOS[0], parseInt((pitchHeight * 0.75) + 5, 10)] + } else { + player.startPOS = [player.originPOS[0], parseInt(pitchHeight * 0.5, 10)] + } + } + } + return matchDetails +} + +function setTopHalfwayToBottomQuarterYPos(matchDetails, attack, defence) { + let { ball } = matchDetails + let [pitchWidth, pitchHeight] = matchDetails.pitchSize + let kickPlayer = attack.players[5] + kickPlayer.hasBall = true + ball.Player = kickPlayer.name + ball.withTeam = attack.name + let ballInCentre = common.isBetween(ball.position[0], (pitchWidth / 4) + 5, (pitchWidth - (pitchWidth / 4) - 5)) + let ballLeft = common.isBetween(ball.position[0], 0, (pitchWidth / 4) + 4) + ball.direction = (ballInCentre) ? 'south' : (ballLeft) ? 'southeast' : 'southwest' + kickPlayer.startPOS = ball.position.map(x => x) + for (let player of attack.players) { + if (player.position == 'GK') player.startPOS = [player.originPOS[0], parseInt(pitchHeight * 0.25, 10)] + else if (['CB', 'LB', 'RB'].includes(player.position)) { + let maxYPOSCheck = parseInt(common.upToMax(ball.position[1] - 100, pitchHeight * 0.5), 10) + player.startPOS = [player.originPOS[0], maxYPOSCheck] + } else if (['CM', 'LM', 'RM'].includes(player.position)) { + let maxYPOSCheck = common.upToMax(ball.position[1] + common.getRandomNumber(150, 300), pitchHeight * 0.75) + if (player.name != kickPlayer.name) player.startPOS = [player.originPOS[0], parseInt(maxYPOSCheck, 10)] + } else { + let maxYPOSCheck = common.upToMax(ball.position[1] + common.getRandomNumber(300, 400), pitchHeight * 0.9) + player.startPOS = [player.originPOS[0], parseInt(maxYPOSCheck, 10)] + } + } + for (let player of defence.players) { + if (['GK', 'CB', 'LB', 'RB'].includes(player.position)) { + player.startPOS = player.originPOS.map(x => x) + } else if (['CM', 'LM', 'RM'].includes(player.position)) { + player.startPOS = [player.originPOS[0], parseInt(pitchHeight * 0.75, 10)] + } else { + player.startPOS = [player.originPOS[0], parseInt(pitchHeight * 0.5, 10)] + } + } + return matchDetails +} + + +function setTopBottomQuarterCentreYPos(matchDetails, attack, defence) { return matchDetails } +function setTopUpperFinalQuarterLeftPos(matchDetails, attack, defence) { return matchDetails } +function setTopLowerFinalQuarterBylineLeftPos(matchDetails, attack, defence) { return matchDetails } +function setTopUpperFinalQuarterRightPos(matchDetails, attack, defence) { return matchDetails } +function setTopLowerFinalQuarterBylineRightPos(matchDetails, attack, defence) { return matchDetails } + + + +//OLD STUFF +// +// +// function setFreekick(ballPosition, team, opposition, side, matchDetails) { - setPos.removeBallFromAllPlayers(matchDetails) + removeBallFromAllPlayers(matchDetails) const [matchWidth, matchHeight] = matchDetails.pitchSize let tempArray = ballPosition team.players[5].startPOS = tempArray.map(x => x) @@ -354,6 +496,17 @@ function setFreekick(ballPosition, team, opposition, side, matchDetails) { } } +function removeBallFromAllPlayers(matchDetails) { + for (let player of matchDetails.kickOffTeam.players) { + player.hasBall = false + } + for (let player of matchDetails.secondTeam.players) { + player.hasBall = false + } +} + module.exports = { - setFreekick + setFreekick, + setTopFreekick, + setBottomFreekick } diff --git a/lib/setPositions.js b/lib/setPositions.js index 9701fd7..7918091 100644 --- a/lib/setPositions.js +++ b/lib/setPositions.js @@ -277,7 +277,7 @@ function closestPlayerToPosition(player, team, position) { function setSetpieceKickOffTeam(matchDetails) { const [matchWidth, matchHeight] = matchDetails.pitchSize let ballPosition = matchDetails.ball.position.map(x => x) - let ballInPenalyBoxX = common.isBetween(ballPosition[0], (matchWidth / 4) - 5, matchWidth - (matchWidth / 4) + 5) + let ballInPenalyBoxX = common.isBetween(ballPosition[0], (matchWidth / 4) + 5, matchWidth - (matchWidth / 4) - 5) let ballInTopPenalyBoxY = common.isBetween(ballPosition[1], 0, (matchHeight / 6) - 5) let ballInBottomPenalyBoxY = common.isBetween(ballPosition[1], matchHeight - (matchHeight / 6) + 5, matchHeight) let attackingTowardsTop = (matchDetails.kickOffTeam.players[0].startPOS[1] > matchHeight / 2) @@ -298,7 +298,7 @@ function setSetpieceKickOffTeam(matchDetails) { function setSetpieceSecondTeam(matchDetails) { const [matchWidth, matchHeight] = matchDetails.pitchSize let ballPosition = matchDetails.ball.position.map(x => x) - let ballInPenalyBoxX = common.isBetween(ballPosition[0], (matchWidth / 4) - 5, matchWidth - (matchWidth / 4) + 5) + let ballInPenalyBoxX = common.isBetween(ballPosition[0], (matchWidth / 4) + 5, matchWidth - (matchWidth / 4) - 5) let ballInBottomPenalyBoxY = common.isBetween(ballPosition[1], matchHeight - (matchHeight / 6) + 5, matchHeight) let ballInTopPenalyBoxY = common.isBetween(ballPosition[1], 0, (matchHeight / 6) - 5) let attackingTowardsTop = (matchDetails.secondTeam.players[0].startPOS[1] > matchHeight / 2) diff --git a/test/lib/set_freekicks.js b/test/lib/set_freekicks.js new file mode 100644 index 0000000..52a3ea5 --- /dev/null +++ b/test/lib/set_freekicks.js @@ -0,0 +1,24 @@ +const common = require('../../lib/common') +const setFreekick = require('../../lib/setFreekicks') + +async function setTopFreekick(iterationFile, ballPosition) { + let matchDetails = await common.readFile(iterationFile) + .catch(function(err) { + throw err.stack + }) + matchDetails.ball.position = ballPosition.map(x => x) + return setFreekick.setTopFreekick(matchDetails) +} +async function setBottomFreekick(iterationFile, ballPosition) { + let matchDetails = await common.readFile(iterationFile) + .catch(function(err) { + throw err.stack + }) + matchDetails.ball.position = ballPosition.map(x => x) + return setFreekick.setBottomFreekick(matchDetails) +} + +module.exports = { + setTopFreekick, + setBottomFreekick +} diff --git a/test/setBottomFreekicksTests.js b/test/setBottomFreekicksTests.js new file mode 100644 index 0000000..1adf7c2 --- /dev/null +++ b/test/setBottomFreekicksTests.js @@ -0,0 +1,530 @@ +const mocha = require('mocha') +const { expect } = require('chai') +const setfreekicks = require('./lib/set_freekicks') +const common = require('../lib/common') + +function runTest() { +// mocha.describe('testFreekicksBottomOwnHalf()', function() { +// mocha.it('freekick in own half - Bottom origin positions', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let { kickOffTeam, secondTeam } = nextJSON +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('north') +// expect(nextJSON.ball.position).to.eql([340, 1000]) +// expect(secondTeam.players[0].startPOS).to.eql([340, 1000]) +// for (let player of secondTeam.players) { +// if (!player.position == 'GK') { +// expect(player.startPOS).to.eql([player.originPOS[0], player.originPOS[1] - 300]) +// } +// } +// for (let player of kickOffTeam.players) { +// if (player.position == 'GK') { +// expect(player.startPOS).to.eql(player.originPOS) +// } else { +// expect(player.startPOS).to.eql(player.originPOS[0], player.originPOS[1] + 100) +// } +// } +// }) +// mocha.it('freekick in own half - Bottom boundary', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let { kickOffTeam, secondTeam } = nextJSON +// let [,pitchHeight] = nextJSON.pitchSize +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('northeast') +// expect(nextJSON.ball.position).to.eql([340, pitchHeight - 1]) +// expect(secondTeam.players[0].startPOS).to.eql([340, pitchHeight - 1]) +// for (let player of secondTeam.players) { +// expect(player.startPOS).to.eql(player.originPOS) +// } +// for (let player of kickOffTeam.players) { +// if (player.position == 'GK') { +// expect(player.startPOS).to.eql(player.originPOS) +// } else { +// expect(player.startPOS).to.eql(player.originPOS[0], player.originPOS[1] + 100) +// } +// } +// }) +// mocha.it('freekick in own half - halfway boundary', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let STgoalie = secondTeam.players[0] + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('north') +// expect(nextJSON.ball.position).to.eql([340, 526]) +// expect(secondTeam.players[3].startPOS).to.eql([340, 526]) +// expect(kickOffTeam.players[3].startPOS).to.eql(secondTeam.players[3].originPOS) +// expect(STgoalie.startPOS).to.eql([STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)]) +// for (let num of [1, 2, 4]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) +// } +// for (let num of [5, 6, 7, 8]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.25, 10)]) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.25, 10) - 5) +// } +// for (let num of [9, 10]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.1, 10)]) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)) +// } +// }) +// }) +// mocha.describe('testFreekicksBottomThirdQuarter()', function() { +// mocha.it('freekick between halfway and last sixth - Bottom center', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('north') +// expect(nextJSON.ball.position).to.eql([400, 500]) +// expect(secondTeam.players[5].startPOS).to.eql([400, 500]) +// expect(kickOffTeam.players[5].startPOS).to.eql([340, parseInt(pitchHeight * 0.25, 10)]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql(thisPlayer.originPOS[0], 600) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) +// } +// for (let num of [6, 7, 8]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.lt(300) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.25, 10)) +// } +// for (let num of [9, 10]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.gt(parseInt((pitchHeight * 0.25) + 50, 10)) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)) +// } +// }) +// mocha.it('freekick between halfway and last sixth - Bottom left', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('northeast') +// expect(nextJSON.ball.position).to.eql([29, 500]) +// expect(kickOffTeam.players[5].startPOS).to.eql([29, 500]) +// expect(secondTeam.players[5].startPOS).to.eql([340, parseInt((pitchHeight * 0.25) + 30, 10)]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(STgKOTgoalieoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql(thisPlayer.originPOS[0], 600) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) +// } +// for (let num of [6, 7, 8]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.lt(300) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.25, 10)) +// } +// for (let num of [9, 10]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.gt(parseInt((pitchHeight * 0.25) - 50, 10)) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)) +// } +// }) +// mocha.it('freekick between halfway and last sixth - Bottom right', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('northwest') +// expect(nextJSON.ball.position).to.eql([655, 500]) +// expect(kickOffTeam.players[5].startPOS).to.eql([655, 500]) +// expect(secondTeam.players[5].startPOS).to.eql([340, parseInt((pitchHeight * 0.25) + 30, 10)]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS).to.eql(thisPlayer.originPOS[0], 600) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) +// } +// for (let num of [6, 7, 8]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.lt(300) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.25, 10)) +// } +// for (let num of [9, 10]) { +// let thisPlayer = secondTeam.players[num] +// let thatPlayer = kickOffTeam.players[num] + +// expect(thisPlayer.startPOS[1]).to.gt(parseInt((pitchHeight * 0.25) - 50, 10)) +// expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)) +// } +// }) +// }) +// mocha.describe('testFreekicksBottomLastQuarter()', function() { +// mocha.it('freekick last sixth - top center', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let playerSpace = -3 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('north') +// expect(nextJSON.ball.position).to.eql([340, parseInt((pitchHeight / 6) + 35, 10)]) +// expect(secondTeam.players[5].startPOS).to.eql([340, parseInt((pitchHeight / 6) + 35, 10)]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// let ballDistanceFromGoalY = nextJSON.ball.position[1] +// let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX + playerSpace, midWayFromBalltoGoalY]) +// playerSpace += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = secondTeam.players[num].startPOS[0] +// let thisYPOSKOT = secondTeam.players[num].startPOS[1] +// let thisXPOSST = kickOffTeam.players[num].startPOS[0] +// let thisYPOSST = kickOffTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// mocha.it('freekick last sixth - Bottom edge of penalty box', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let playerSpace = -3 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('north') +// expect(nextJSON.ball.position).to.eql([340, parseInt((pitchHeight / 6) - 4, 10)]) +// expect(secondTeam.players[5].startPOS).to.eql([340, parseInt((pitchHeight / 6) - 4, 10)]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// let ballDistanceFromGoalY = nextJSON.ball.position[1] +// let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX + playerSpace, midWayFromBalltoGoalY]) +// playerSpace += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = secondTeam.players[num].startPOS[0] +// let thisYPOSKOT = secondTeam.players[num].startPOS[1] +// let thisXPOSST = kickOffTeam.players[num].startPOS[0] +// let thisYPOSST = kickOffTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// mocha.it('freekick last sixth - Bottom team top left', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let playerSpace = -3 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('east') +// expect(nextJSON.ball.position).to.eql([10, 47]) +// expect(secondTeam.players[5].startPOS).to.eql([10, 47]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// let ballDistanceFromGoalY = nextJSON.ball.position[1] +// let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, midWayFromBalltoGoalY + playerSpace]) +// playerSpace += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] +// let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] +// let thisXPOSST = secondTeam.players[num].startPOS[0] +// let thisYPOSST = secondTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// mocha.it('freekick and last sixth - Bottom team bottom right', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let playerSpace = -3 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('west') +// expect(nextJSON.ball.position).to.eql([600, 27]) +// expect(secondTeam.players[5].startPOS).to.eql([600, 27]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// let ballDistanceFromGoalY = nextJSON.ball.position[1] +// let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, midWayFromBalltoGoalY + playerSpace]) +// playerSpace += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = secondTeam.players[num].startPOS[0] +// let thisYPOSKOT = secondTeam.players[num].startPOS[1] +// let thisXPOSST = kickOffTeam.players[num].startPOS[0] +// let thisYPOSST = kickOffTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// mocha.it('freekick last sixth - Bottom team bottom left goal line', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let firstWallPosition = 1 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('east') +// expect(nextJSON.ball.position).to.eql([10, 1]) +// expect(secondTeam.players[5].startPOS).to.eql([10, 1]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, firstWallPosition]) +// firstWallPosition += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = secondTeam.players[num].startPOS[0] +// let thisYPOSKOT = secondTeam.players[num].startPOS[1] +// let thisXPOSST = kickOffTeam.players[num].startPOS[0] +// let thisYPOSST = kickOffTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// mocha.it('freekick last sixth - Bottom team bottom right goal line', async() => { +// let itlocation = './init_config/iteration.json' +// let nextJSON = await setfreekicks.setBottomFreekick(itlocation) +// let [pitchWidth, pitchHeight] = nextJSON.pitchSize +// let { kickOffTeam, secondTeam } = nextJSON +// let KOTgoalie = kickOffTeam.players[0] +// let STgoalie = secondTeam.players[0] +// let firstWallPosition = 1 + +// expect(nextJSON).to.be.an('object') +// expect(nextJSON.ball.direction).to.eql('west') +// expect(nextJSON.ball.position).to.eql([600, 1]) +// expect(secondTeam.players[5].startPOS).to.eql([600, 1]) +// expect(STgoalie.startPOS).to.eql(STgoalie.originPOS[0], parseInt(pitchHeight * 0.75, 10)) +// expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS) +// for (let num of [1, 2, 3, 4]) { +// let thisPlayer = secondTeam.players[num].startPOS +// let thatPlayer = kickOffTeam.players[num].startPOS +// let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) +// let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) +// if (thisPlayer.position == 'CB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) +// } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { +// expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.33, 10)]) +// } +// expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, firstWallPosition]) +// firstWallPosition += 2 +// } +// let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] +// let boundaryY = [0, (pitchHeight / 6) + 5] +// for (let num of [5, 6, 7, 8, 9, 10]) { +// let thisXPOSKOT = secondTeam.players[num].startPOS[0] +// let thisYPOSKOT = secondTeam.players[num].startPOS[1] +// let thisXPOSST = kickOffTeam.players[num].startPOS[0] +// let thisYPOSST = kickOffTeam.players[num].startPOS[1] + +// if (num != 5) { +// expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) +// } else { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([6, 7].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// if ([8, 9, 10].includes(num)) { +// expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) +// expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) +// } +// } +// }) +// }) +} + +module.exports = { + runTest +} diff --git a/test/setTopFreekicksTests.js b/test/setTopFreekicksTests.js new file mode 100644 index 0000000..95e72d9 --- /dev/null +++ b/test/setTopFreekicksTests.js @@ -0,0 +1,524 @@ +const mocha = require('mocha') +const { expect } = require('chai') +const setfreekicks = require('./lib/set_freekicks') +const common = require('../lib/common') + +function runTest() { + mocha.describe('testFreekicksTopOwnHalf()', function () { + mocha.it('freekick in own half - top boundary', async () => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [340, 1]) + let { kickOffTeam, secondTeam } = nextJSON + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('south') + expect(nextJSON.ball.position).to.eql([340, 1]) + expect(kickOffTeam.players[0].startPOS).to.eql([340, 1]) + for (let player of kickOffTeam.players) { + if (player.position != 'GK') expect(player.startPOS).to.eql(player.originPOS) + } + for (let player of secondTeam.players) { + if (player.position == 'GK') expect(player.startPOS).to.eql(player.originPOS) + if (player.position != 'GK') expect(player.startPOS).to.eql([player.originPOS[0], player.originPOS[1] - 100]) + } + }) + mocha.it('freekick in own half - top origin positions', async () => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [340, 101]) + let { kickOffTeam, secondTeam } = nextJSON + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('south') + expect(nextJSON.ball.position).to.eql([340, 101]) + expect(kickOffTeam.players[0].startPOS).to.eql([340, 101]) + for (let player of kickOffTeam.players) { + if (player.position != 'GK') { + expect(player.startPOS).to.eql([player.originPOS[0], player.originPOS[1] + 300]) + } + } + for (let player of secondTeam.players) { + if (player.position == 'GK') { + expect(player.startPOS).to.eql(player.originPOS) + } else { + expect(player.startPOS).to.eql([player.originPOS[0], player.originPOS[1] - 100]) + } + } + }) + mocha.it('freekick in own half - halfway boundary', async () => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [340, 524]) + let [, pitchHeight] = nextJSON.pitchSize + let { kickOffTeam, secondTeam } = nextJSON + let KOTgoalie = kickOffTeam.players[0] + + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('south') + expect(nextJSON.ball.position).to.eql([340, 524]) + expect(kickOffTeam.players[3].startPOS).to.eql([340, 524]) + expect(secondTeam.players[3].startPOS).to.eql(secondTeam.players[3].originPOS) + expect(KOTgoalie.startPOS).to.eql([KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)]) + for (let num of [1, 2, 4]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) + } + for (let num of [5, 6, 7, 8]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.75, 10)]) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.75, 10) + 5]) + } + for (let num of [9, 10]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], 824]) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + } + }) + }) + mocha.describe('testFreekicksTopHalfwayToThirdQuarter()', function() { + mocha.it('freekick between halfway and last quarter - top center', async() => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [400, 550]) + let [, pitchHeight] = nextJSON.pitchSize + let { kickOffTeam, secondTeam } = nextJSON + let KOTgoalie = kickOffTeam.players[0] + let STgoalie = secondTeam.players[0] + + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('south') + expect(nextJSON.ball.position).to.eql([400, 550]) + expect(kickOffTeam.players[5].startPOS).to.eql([400, 550]) + expect(secondTeam.players[5].startPOS).to.eql([80, parseInt(pitchHeight * 0.75, 10)]) + expect(KOTgoalie.startPOS).to.eql([KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)]) + expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + for (let num of [1, 2, 3, 4]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], 450]) + expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) + } + for (let num of [6, 7, 8]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(699) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.75, 10)]) + } + for (let num of [9, 10]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(849) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + } + }) + mocha.it('freekick between halfway and last quarter - top left', async() => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [29, 550]) + let [, pitchHeight] = nextJSON.pitchSize + let { kickOffTeam, secondTeam } = nextJSON + let KOTgoalie = kickOffTeam.players[0] + let STgoalie = secondTeam.players[0] + + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('southeast') + expect(nextJSON.ball.position).to.eql([29, 550]) + expect(kickOffTeam.players[5].startPOS).to.eql([29, 550]) + expect(secondTeam.players[5].startPOS).to.eql([80, parseInt((pitchHeight * 0.75), 10)]) + expect(KOTgoalie.startPOS).to.eql([KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)]) + expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + for (let num of [1, 2, 3, 4]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], 450]) + expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) + } + for (let num of [6, 7, 8]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(699) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.75, 10)]) + } + for (let num of [9, 10]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(849) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + } + }) + mocha.it('freekick between halfway and last quarter - top right', async() => { + let itlocation = './init_config/iteration.json' + let nextJSON = await setfreekicks.setTopFreekick(itlocation, [655, 550]) + let [, pitchHeight] = nextJSON.pitchSize + let { kickOffTeam, secondTeam } = nextJSON + let KOTgoalie = kickOffTeam.players[0] + let STgoalie = secondTeam.players[0] + + expect(nextJSON).to.be.an('object') + expect(nextJSON.ball.direction).to.eql('southwest') + expect(nextJSON.ball.position).to.eql([655, 550]) + expect(kickOffTeam.players[5].startPOS).to.eql([655, 550]) + expect(secondTeam.players[5].startPOS).to.eql([80, parseInt((pitchHeight * 0.75), 10)]) + expect(KOTgoalie.startPOS).to.eql([KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)]) + expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + for (let num of [1, 2, 3, 4]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], 450]) + expect(thatPlayer.startPOS).to.eql(thatPlayer.originPOS) + } + for (let num of [6, 7, 8]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(699) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.75, 10)]) + } + for (let num of [9, 10]) { + let thisPlayer = kickOffTeam.players[num] + let thatPlayer = secondTeam.players[num] + + expect(thisPlayer.startPOS[1]).to.gt(849) + expect(thatPlayer.startPOS).to.eql([thatPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + } + }) + }) + // mocha.describe('testFreekicksTopLastQuarter()', function() { + // mocha.it('freekick last quarter - top center', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let playerSpace = -3 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('south') + // expect(nextJSON.ball.position).to.eql([340, parseInt(pitchHeight - (pitchHeight / 6) - 35, 10)]) + // expect(kickOffTeam.players[5].startPOS).to.eql([340, parseInt(pitchHeight - (pitchHeight / 6) - 35, 10)]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // let ballDistanceFromGoalY = (pitchHeight - nextJSON.ball.position[1]) + // let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX + playerSpace, midWayFromBalltoGoalY]) + // playerSpace += 2 + // } + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // mocha.it('freekick last quarter - top edge of penalty box', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let playerSpace = -3 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('south') + // expect(nextJSON.ball.position).to.eql([340, parseInt(pitchHeight - (pitchHeight / 6) + 4, 10)]) + // expect(kickOffTeam.players[5].startPOS).to.eql([340, parseInt(pitchHeight - (pitchHeight / 6) + 4, 10)]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // let ballDistanceFromGoalY = (pitchHeight - nextJSON.ball.position[1]) + // let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX + playerSpace, midWayFromBalltoGoalY]) + // playerSpace += 2 + // } + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // mocha.it('freekick last quarter - top team bottom left', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let playerSpace = -3 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('east') + // expect(nextJSON.ball.position).to.eql([10, pitchHeight - 47]) + // expect(kickOffTeam.players[5].startPOS).to.eql([10, pitchHeight - 47]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // let ballDistanceFromGoalY = (pitchHeight - nextJSON.ball.position[1]) + // let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, midWayFromBalltoGoalY + playerSpace]) + // playerSpace += 2 + // } + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // mocha.it('freekick and last quarter - top team bottom right', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let playerSpace = -3 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('west') + // expect(nextJSON.ball.position).to.eql([600, pitchHeight - 25]) + // expect(kickOffTeam.players[5].startPOS).to.eql([600, pitchHeight - 25]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // let ballDistanceFromGoalY = (pitchHeight - nextJSON.ball.position[1]) + // let midWayFromBalltoGoalY = parseInt((nextJSON.ball.position[1] - ballDistanceFromGoalY) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, midWayFromBalltoGoalY + playerSpace]) + // playerSpace += 2 + // } + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // mocha.it('freekick last quarter - top team bottom left goal line', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let firstWallPosition = pitchHeight - 1 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('east') + // expect(nextJSON.ball.position).to.eql([10, pitchHeight - 1]) + // expect(kickOffTeam.players[5].startPOS).to.eql([10, pitchHeight - 1]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, firstWallPosition]) + // firstWallPosition += 2 + // } + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // mocha.it('freekick last quarter - top team bottom right goal line', async() => { + // let itlocation = './init_config/iteration.json' + // let nextJSON = await setfreekicks.setTopFreekick(itlocation) + // let [pitchWidth, pitchHeight] = nextJSON.pitchSize + // let { kickOffTeam, secondTeam } = nextJSON + // let KOTgoalie = kickOffTeam.players[0] + // let STgoalie = secondTeam.players[0] + // let firstWallPosition = pitchHeight - 1 + + // expect(nextJSON).to.be.an('object') + // expect(nextJSON.ball.direction).to.eql('west') + // expect(nextJSON.ball.position).to.eql([600, pitchHeight - 1]) + // expect(kickOffTeam.players[5].startPOS).to.eql([600, pitchHeight - 1]) + // expect(KOTgoalie.startPOS).to.eql(KOTgoalie.originPOS[0], parseInt(pitchHeight * 0.25, 10)) + // expect(STgoalie.startPOS).to.eql(STgoalie.originPOS) + // for (let num of [1, 2, 3, 4]) { + // let thisPlayer = kickOffTeam.players[num].startPOS + // let thatPlayer = secondTeam.players[num].startPOS + // let ballDistanceFromGoalX = nextJSON.ball.position[0] - (pitchWidth / 2) + // let midWayFromBalltoGoalX = parseInt((nextJSON.ball.position[0] - ballDistanceFromGoalX) / 2, 10) + // if (thisPlayer.position == 'CB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.5, 10)]) + // } else if (thisPlayer.position == 'LB' || thisPlayer.position == 'RB') { + // expect(thisPlayer.startPOS).to.eql([thisPlayer.originPOS[0], parseInt(pitchHeight * 0.66, 10)]) + // } + // expect(thatPlayer.startPOS).to.eql([midWayFromBalltoGoalX, firstWallPosition]) + // firstWallPosition += 2 + // } + // for (let num of [5, 6, 7, 8, 9, 10]) { + // let thisXPOSKOT = kickOffTeam.players[num].startPOS[0] + // let thisYPOSKOT = kickOffTeam.players[num].startPOS[1] + // let thisXPOSST = secondTeam.players[num].startPOS[0] + // let thisYPOSST = secondTeam.players[num].startPOS[1] + // let boundaryX = [(pitchWidth / 4) - 5, (pitchWidth - (pitchWidth / 4) + 5)] + // let boundaryY = [pitchHeight, pitchHeight - (pitchHeight / 6) + 5] + + // if (num != 5) { + // expect(true).to.eql(common.isBetween(thisXPOSKOT, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSKOT, boundaryY[0], boundaryY[1])) + // } else { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([6, 7].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // if ([8, 9, 10].includes(num)) { + // expect(true).to.eql(common.isBetween(thisXPOSST, boundaryX[0], boundaryX[1])) + // expect(true).to.eql(common.isBetween(thisYPOSST, boundaryY[0], boundaryY[1])) + // } + // } + // }) + // }) +} + +module.exports = { + runTest +} diff --git a/test/test.js b/test/test.js index 8cb58c4..82c5441 100644 --- a/test/test.js +++ b/test/test.js @@ -5,6 +5,8 @@ const testD = require('./keepInBoundaries') const testE = require('./miscPositionChecks') const testF = require('./setPositionTests') const testG = require('./relativePositions') +const testH = require('./setTopFreekicksTests') +const testI = require('./setBottomFreekicksTests') testA.runTest() testB.runTest() @@ -13,3 +15,5 @@ testD.runTest() testE.runTest() testF.runTest() testG.runTest() +testH.runTest() +testI.runTest()