Skip to content

Commit

Permalink
Merge pull request #133 from UTDallasEPICS/Damian2
Browse files Browse the repository at this point in the history
Score tracking for Ties
  • Loading branch information
OfekShaltiel-UTD authored Dec 6, 2024
2 parents 4de0f80 + 1f4a686 commit 6e251b4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
Binary file modified prisma/dev.db
Binary file not shown.
33 changes: 27 additions & 6 deletions server/Game_Manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let timer: number = 0
const timer_duration: number = parseInt(`${process.env.TIMER_DURATION}`) // this is the initial timer duration, in seconds
let confirmation_timer: number = 0
const confirmation_timer_duration: number = parseInt(`${process.env.CONFIRMATION_TIMER_DURATION}`) // this is the time given to players to confirm, in seconds
let score1: number = 10
let score2: number = 2
let score1: number = 8
let score2: number = 5
enum GAME_STATE { NOT_PLAYING, SEND_CONFIRM, PLAYING, RESETTING }
let game_state: GAME_STATE = GAME_STATE.NOT_PLAYING
let robots_ready: boolean = true
Expand Down Expand Up @@ -166,6 +166,9 @@ const gameCycle = setInterval( async () => {
{"user_id": players[1]["user_id"]}] })
})




// store played match in database
await prisma.match.create({
data: {
Expand Down Expand Up @@ -212,8 +215,7 @@ const gameCycle = setInterval( async () => {
games: {increment: 1},
ratio: ratio1,
goals: {increment: score1}
}

}
}),

prisma.player.update({
Expand All @@ -229,7 +231,7 @@ const gameCycle = setInterval( async () => {
})
])
}
else{
else if(score2 > score1){
let ratio2 = (player2 as PlayerType).losses ? ((player2 as PlayerType).wins + 1) / ((player2 as PlayerType).losses) : ++(player2 as PlayerType).wins
await prisma.$transaction([
prisma.player.update({
Expand Down Expand Up @@ -257,8 +259,27 @@ const gameCycle = setInterval( async () => {
})
])
}

else{
await prisma.$transaction([
prisma.player.update({
where: {user_id: players[0]["user_id"]},
data: {
games: {increment: 1},
goals: {increment: score1}
}
}),

prisma.player.update({
where: {user_id: players[1]["user_id"]},
data: {
games: {increment: 1},
goals: {increment: score2}
}
})
])

}

players.splice(0, 2)
robots_ready = true
timer = 0
Expand Down

0 comments on commit 6e251b4

Please sign in to comment.