xxxxxxxxxx
703
let digits = {0:"0️⃣",1:"1️⃣",2:"2️⃣",3:"3️⃣",4:"4️⃣",5:"5️⃣",6:"6️⃣",7:"7️⃣",8:"8️⃣",9:"9️⃣"};
let digits_to_auction;
let player_auctioned_digits=[];
let player_auctioned_digits_raw=[];
let agent_auctioned_digits=[];
let agent_auctioned_digits_raw=[];
let playerTokens;
let agentTokens;
let playerCurrentBid ;
let agentCurrentBid;
let digit_prices={};
let gameOver;
let all_rounds_over;
const coin_width=50;
const coin_height = 10;
const button_length=40;
let minus_button1,plus_button1,minus_button2,plus_button2,minus_button5,plus_button5,go_button;
let select_index_label;
let player_final_number;
let won_or_not;
let RoundNo=1;
const TotalRounds = 20
const max_coins_per_stack=10;
const maxTokens = 30;
const SCORE_PANEL_HEIGHT = 100;
const TABLE_CELL_HEIGHT=15;
let player_round_scores={};
let agent_round_scores={};
let fullname_ip,joining_code_ip,submin_btn;
let first_joining = true;
let user_name="xxx";
let error_msg_at_joining='';
let robo_img,man_img;
let robo_img_head;
let lock_bid=false;
let lock_bid_btn;
const WIN_WIDTH=1280
const WIN_HEIGHT = 720
const APP_WIDTH=WIN_WIDTH/2;
const APP_HEIGHT=WIN_HEIGHT/2;
let W10 = APP_WIDTH/40;
let H10 = APP_WIDTH/60;
let player_win_status={}
let agent_win_status={}
let lock_error="";
let agent_wins;
let agent_loses;
let player_wins;
let player_loses;
let player_cup;
let agent_cup;
// joining code
const joining_code ='123'; // need to be changed for every game session
function preload() {
robo_img = loadImage('robo_typing.png');
// robo_img_head = loadImage('robo_typing_small.png');
man_img = loadImage('man_typing.png');
}
function score_toString(score){
if(score==-2) return '-';
else return str(score);
}
function mid_setup(){
select_index_label = ""
player_final_number=""
agent_final_number=""
won_or_not =""
player_auctioned_digits = []
player_auctioned_digits_raw = []
agent_auctioned_digits = []
agent_auctioned_digits_raw = []
// pixelDensity(1);
textAlign(CENTER,CENTER);
digits_to_auction = shuffle([0,1,2,3,4,5,6,7,8,9]);
playerCurrentBid=0;
agentCurrentBid=0;
playerTokens=maxTokens;
agentTokens= maxTokens;
gameOver=false;
all_rounds_over = false;
}
function setup() {
// createCanvas(APP_WIDTH, APP_HEIGHT+SCORE_PANEL_HEIGHT);
createCanvas(WIN_WIDTH, WIN_HEIGHT);
if(first_joining){
fullname_ip = createInput('');
joining_code_ip = createInput('');
submit_btn = createButton('Join');
submit_btn.mousePressed(enter_the_game);
}
minus_button1 = createButton('➖1');
plus_button1 = createButton('➕1');
minus_button2 = createButton('➖2');
plus_button2 = createButton('➕2');
minus_button5 = createButton('➖5');
plus_button5 = createButton('➕5');
go_button = createButton('GO')
lock_bid_btn = createButton('🔓');
lock_bid_btn.html('🔓');
minus_button1.hide();
plus_button1.hide();
minus_button2.hide();
plus_button2.hide();
minus_button5.hide();
plus_button5.hide();
go_button.hide();
lock_bid_btn.hide();
mid_setup(); // midesetup
lock_bid_btn.style('font-size', '30px');
lock_bid_btn.style('background-color','#white')
minus_button1.style('font-size', '25px');
minus_button1.style('background-color','#9E9E9E')
plus_button1.style('font-size', '25px');
plus_button1.style('background-color','#9E9E9E');
minus_button2.style('font-size', '25px');
minus_button2.style('background-color','#607D8B');
plus_button2.style('font-size', '25px');
plus_button2.style('background-color','#607D8B');
minus_button5.style('font-size', '25px');
minus_button5.style('background-color','#795548');
plus_button5.style('font-size', '25px');
plus_button5.style('background-color','#795548');
go_button.style('font-size', '30px');
go_button.style('background-color','green')
minus_button1.mousePressed(bidChange);
plus_button1.mousePressed(bidChange);
minus_button2.mousePressed(bidChange);
plus_button2.mousePressed(bidChange);
minus_button5.mousePressed(bidChange);
plus_button5.mousePressed(bidChange);
lock_bid_btn.mousePressed(lock_bid_fn);
go_button.mousePressed(go);
minus_button1.position(WIN_WIDTH/2+APP_WIDTH/3-2*minus_button1.width/2,WIN_HEIGHT/3-3*H10);
plus_button1.position(WIN_WIDTH/2+APP_WIDTH/3-2*minus_button1.width/2,WIN_HEIGHT/3+H10);
minus_button2.position(WIN_WIDTH/2+APP_WIDTH/3-5.5*minus_button1.width/2,WIN_HEIGHT/3-3*H10);
plus_button2.position(WIN_WIDTH/2+APP_WIDTH/3-5.5*minus_button1.width/2,WIN_HEIGHT/3+H10);
minus_button5.position(WIN_WIDTH/2+APP_WIDTH/3-9*minus_button1.width/2,WIN_HEIGHT/3-3*H10);
plus_button5.position(WIN_WIDTH/2+APP_WIDTH/3-9*minus_button1.width/2,WIN_HEIGHT/3+H10);
go_button.position(WIN_WIDTH/2+APP_WIDTH/3+8*W10,WIN_HEIGHT/3-H10);
lock_bid_btn.position(WIN_WIDTH/2+APP_WIDTH/3+2*minus_button1.width/2,WIN_HEIGHT/3-H10);
for(let r=1;r<=TotalRounds;r++){
player_round_scores[r]=-2;
player_win_status[r] = '';
}
for(let r=1;r<=TotalRounds;r++){
agent_round_scores[r]=-2;
agent_win_status[r] = '';
}
agent_wins=0;
agent_loses=0;
player_wins=0;
player_loses=0;
player_cup='';
agent_cup='';
}
function lock_bid_fn(){
if(playerCurrentBid>0){
lock_bid_btn.html("🔒");
lock_bid=true;
let tryagentCurrentBid = int(random(digits_to_auction[digits_to_auction.length-1]-3,digits_to_auction[digits_to_auction.length-1]+3));
if(tryagentCurrentBid <0){
agentCurrentBid =1;
}
else if(tryagentCurrentBid > agentTokens){
agentCurrentBid =agentTokens;
}
else{
agentCurrentBid = max(tryagentCurrentBid,1);
}
agentTokens -=agentCurrentBid;
go_button.show();
}
else{
if(!gameOver){
lock_error="Please bid coins first, then lock it!"
}
}
}
function enter_the_game(){
if(joining_code_ip.value()==joining_code){
user_name = fullname_ip.value();
first_joining=false;
error_msg_at_joining='';
fullname_ip.hide();
joining_code_ip.hide();
submit_btn.hide();
minus_button1.show()
plus_button1.show()
minus_button2.show()
plus_button2.show()
minus_button5.show()
plus_button5.show()
// go_button.show()
lock_bid_btn.show();
return;
}
else if(joining_code_ip.value()=='' || fullname_ip.value()==''){
error_msg_at_joining = 'Please Enter Full Name/Joining Code details.'
}
else{
error_msg_at_joining = 'You Entered Invalid Joining Code.'
}
}
function draw(){
if(first_joining){
background('#9E9E9E');
textSize(15);
fill('black');
text('Full Name',WIN_WIDTH/2 - fullname_ip.width/2+70,APP_HEIGHT/4-4*H10);
fullname_ip.position(WIN_WIDTH/2 - fullname_ip.width/2,APP_HEIGHT/4-2*H10);
text('Joining Code',WIN_WIDTH/2 - fullname_ip.width/2+70,APP_HEIGHT/2-4*H10);
joining_code_ip.position(WIN_WIDTH/2 - joining_code_ip.width/2,APP_HEIGHT/2-2*H10);
submit_btn.position(WIN_WIDTH/2 - submit_btn.width/2,3*APP_HEIGHT/5-2*H10);
textSize(15);
fill('red');
text(error_msg_at_joining,APP_WIDTH/2,APP_HEIGHT);
}
else{
after_join();
}
}
function after_join() {
background(255,255,255);
//Score Table
image(robo_img, WIN_WIDTH/2+3*APP_WIDTH/4, 2*H10,15*H10,15*H10); // robo image
image(man_img, WIN_WIDTH/2+APP_WIDTH/16, 2*H10,15*H10,15*H10); // man image
//lock-error
fill('red');
textSize(12);
text(lock_error,WIN_WIDTH/2+APP_WIDTH/3-minus_button1.width/2,WIN_HEIGHT/3+6*H10);
line(WIN_WIDTH/2,APP_HEIGHT,WIN_WIDTH/2+APP_WIDTH,APP_HEIGHT);
line(WIN_WIDTH/2,APP_HEIGHT-2*TABLE_CELL_HEIGHT,WIN_WIDTH/2+APP_WIDTH,APP_HEIGHT-2*TABLE_CELL_HEIGHT);
fill('#F44336')
textSize(20);
textStyle(BOLD);
text( `SCORE TABLE`,WIN_WIDTH/2+APP_WIDTH/2-W10,APP_HEIGHT-TABLE_CELL_HEIGHT);
// win-lose record
fill('black');
textSize(12);
text(`🙍🏻♂️: ${player_wins} - ${player_loses} ${player_cup}`,WIN_WIDTH/2+APP_WIDTH/5,APP_HEIGHT-TABLE_CELL_HEIGHT);
text(`🤖: ${agent_wins} - ${agent_loses} ${agent_cup}`,WIN_WIDTH/2+APP_WIDTH/2+APP_WIDTH/5,APP_HEIGHT-TABLE_CELL_HEIGHT);
text( "🙎🏻♂️",WIN_WIDTH/2+APP_WIDTH/6+APP_WIDTH/12,APP_HEIGHT-TABLE_CELL_HEIGHT/3+2*TABLE_CELL_HEIGHT);
text( "🤖",WIN_WIDTH/2+APP_WIDTH/6+3*APP_WIDTH/12,APP_HEIGHT-TABLE_CELL_HEIGHT/3+2*TABLE_CELL_HEIGHT);
// image(robo_img,APP_WIDTH/6+3*APP_WIDTH/12-5,APP_HEIGHT-TABLE_CELL_HEIGHT/2-8,15,15);
text( "🙎🏻♂️",WIN_WIDTH/2+APP_WIDTH/2+APP_WIDTH/6+APP_WIDTH/12,APP_HEIGHT-TABLE_CELL_HEIGHT/3+2*TABLE_CELL_HEIGHT);
text( "🤖",WIN_WIDTH/2+APP_WIDTH/2+APP_WIDTH/6+3*APP_WIDTH/12,APP_HEIGHT-TABLE_CELL_HEIGHT/3+2*TABLE_CELL_HEIGHT);
// image(robo_img,APP_WIDTH/2+APP_WIDTH/6+3*APP_WIDTH/12-5,APP_HEIGHT-TABLE_CELL_HEIGHT/2-8,15,15);
strokeWeight(4);
line(WIN_WIDTH/2+APP_WIDTH/2,APP_HEIGHT-H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2+APP_WIDTH/2,height-5*H10+2*TABLE_CELL_HEIGHT);
strokeWeight(2);
strokeWeight(2);
line(WIN_WIDTH/2+APP_WIDTH/6,APP_HEIGHT-H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2+APP_WIDTH/6,height-5*H10+2*TABLE_CELL_HEIGHT);
line(WIN_WIDTH/2,APP_HEIGHT-4*H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2,height-5*H10+2*TABLE_CELL_HEIGHT);
line(WIN_WIDTH/2+2*APP_WIDTH/6,APP_HEIGHT-H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2+2*APP_WIDTH/6,height-5*H10+2*TABLE_CELL_HEIGHT);
line(WIN_WIDTH/2+APP_WIDTH/2+2*APP_WIDTH/6,APP_HEIGHT-H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2+APP_WIDTH/2+2*APP_WIDTH/6,height-5*H10+2*TABLE_CELL_HEIGHT);
line(WIN_WIDTH/2+APP_WIDTH/2+APP_WIDTH/6,APP_HEIGHT-H10+TABLE_CELL_HEIGHT,WIN_WIDTH/2+APP_WIDTH/2+APP_WIDTH/6,height-5*H10+2*TABLE_CELL_HEIGHT);
line(WIN_WIDTH-2,APP_HEIGHT-4*H10+TABLE_CELL_HEIGHT,WIN_WIDTH-2,height-5*H10+2*TABLE_CELL_HEIGHT);
for(let i=0;i<=TotalRounds/2;i++)
line(WIN_WIDTH/2,APP_HEIGHT+2*TABLE_CELL_HEIGHT*(i+1)+H10,WIN_WIDTH/2+APP_WIDTH,APP_HEIGHT+2*TABLE_CELL_HEIGHT*(i+1)+H10);
for(let roundNo=1;roundNo<=TotalRounds;roundNo++){
fill('#412014')
textSize(10);
text( `Round No:${roundNo}`,35+(floor((roundNo-1)/(TotalRounds/2)))*APP_WIDTH/2+WIN_WIDTH/2,APP_HEIGHT+2*TABLE_CELL_HEIGHT*((roundNo-1)%(TotalRounds/2))+H10*2+2*TABLE_CELL_HEIGHT);
fill('#3F51B5')
textSize(10);
text( `${score_toString(player_round_scores[roundNo])} ${player_win_status[roundNo]}`,APP_WIDTH/4+(floor((roundNo-1)/(TotalRounds/2)))*APP_WIDTH/2+WIN_WIDTH/2,APP_HEIGHT+2*TABLE_CELL_HEIGHT*((roundNo-1)%(TotalRounds/2))+H10*2+2*TABLE_CELL_HEIGHT);
text( `${score_toString(agent_round_scores[roundNo])} ${agent_win_status[roundNo]}`,WIN_WIDTH/2+APP_WIDTH/4+(floor((roundNo-1)/(TotalRounds/2)))*APP_WIDTH/2+APP_WIDTH/6,APP_HEIGHT+2*TABLE_CELL_HEIGHT*((roundNo-1)%(TotalRounds/2))+H10*2+2*TABLE_CELL_HEIGHT);
}
fill('red');
textSize(15);
text(select_index_label,APP_WIDTH/2,50);
//Display Current Digit
// textAlign(CENTER,CENTER);
fill(0);
textSize(30);
text(`Digit for Auction: ${digits[digits_to_auction[digits_to_auction.length-1]]}`,APP_WIDTH/2,8*H10);
line(0,10*H10,APP_WIDTH,10*H10);//line seperator below auction
// Display player tokens
textSize(40);
text("🙍🏻♂️",APP_WIDTH/10,150); //player
textSize(15);
text(` Coins:💰${playerTokens}`,APP_WIDTH/10,20*H10);
// Display agent tokens
textSize(40);
text("🤖",3*APP_WIDTH/4 +20+APP_WIDTH/10,150); //agent
// image(robo_img,3*APP_WIDTH/4 +APP_WIDTH/10,135,40,40);
textSize(15);
text(` Coins:💰${agentTokens}`,3*APP_WIDTH/4 +20+APP_WIDTH/10,20*H10);
line(0,22*H10,APP_WIDTH,22*H10);//line seperator for coins and bidding
//vertical seperator
line(APP_WIDTH/4 -20,34*H10,APP_WIDTH/4 -20,10*H10);
line(APP_WIDTH/2,34*H10,APP_WIDTH/2,10*H10);
line(3*APP_WIDTH/4 +20,34*H10,3*APP_WIDTH/4 +20,10*H10);
line(APP_WIDTH,34*H10,APP_WIDTH,10*H10);
//coins stacking for player
// let sp = 0;
fill('gold')
for (let t=0; t<playerTokens;t++){
rect(APP_WIDTH/4 - 25+10+floor(t/max_coins_per_stack)*55,20*H10-(t%max_coins_per_stack)*coin_height,coin_width,coin_height,5);
textSize(10);
text("💵",APP_WIDTH/4 -25 +10+floor(t/max_coins_per_stack)*55+coin_width/2,20*H10-(t%max_coins_per_stack)*coin_height+coin_height/2)
}
//Display playerCurrentBid
textSize(15);
fill('black');
text(`🙍🏻♂️ Bidding:💰${playerCurrentBid}`,APP_WIDTH/10,32*H10)
line(0,34*H10,APP_WIDTH,34*H10);//line seperator below bidding
fill('gold')
for (let b=0; b<playerCurrentBid;b++){
rect(APP_WIDTH/4 -25 +10+floor(b/max_coins_per_stack)*55,32*H10-(b%max_coins_per_stack)*coin_height,coin_width,coin_height,5);
textSize(10);
text("💵",APP_WIDTH/4 -25+10+floor(b/max_coins_per_stack)*55+coin_width/2,32*H10-(b%max_coins_per_stack)*coin_height+coin_height/2)
}
// coins stacking for agent
// let sp_ = 0;
fill('#8BC34A')
for (let t=0; t<agentTokens;t++){
rect(APP_WIDTH/2 -5+10+floor(t/max_coins_per_stack)*55,20*H10-(t%max_coins_per_stack)*coin_height,coin_width,coin_height,5);
textSize(10);
text("💵",APP_WIDTH/2 -5 +10+floor(t/max_coins_per_stack)*55+coin_width/2,20*H10-(t%max_coins_per_stack)*coin_height+coin_height/2)
}
//Display agnetCurrentBid
textSize(15);
fill('black');
text(`🤖 Bidding:💰${agentCurrentBid}`,3*APP_WIDTH/4 +2*H10+APP_WIDTH/10,32*H10)
// line(0,30*H10,APP_WIDTH,30*H10);//line seperator below bidding
fill('#8BC34A')
for (let b=0; b<agentCurrentBid;b++){
rect(APP_WIDTH/2 -5 +10+floor(b/max_coins_per_stack)*55,32*H10-(b%max_coins_per_stack)*coin_height,coin_width,coin_height,5);
textSize(10);
text("💵",APP_WIDTH/2 -5+10+floor(b/max_coins_per_stack)*55+coin_width/2,32*H10-(b%max_coins_per_stack)*coin_height+coin_height/2)
}
//Display Digits aquired
textSize(20);
fill('navy')
text(won_or_not,APP_WIDTH/2,2*WIN_HEIGHT/3);
//player digits
textSize(15);
fill('#E91E63')
textStyle(BOLD)
text("DIGITS WON BY 🙍🏻♂️",APP_WIDTH/5,38*H10);
text(`${player_auctioned_digits.join(" ")}`,APP_WIDTH/4-player_auctioned_digits.length*5,40*H10);
//Agent digits
textSize(15);
fill('#3F51B5')
textStyle(BOLD)
text("DIGITS WON BY 🤖",APP_WIDTH/2+APP_WIDTH/4,38*H10);
text(`${agent_auctioned_digits.join(" ")}`,APP_WIDTH/2+APP_WIDTH/4-player_auctioned_digits.length*5,40*H10);
textStyle(NORMAL)
// Rounds Left
textSize(12);
fill('#673AB7')
textStyle(BOLD)
text( `Round No: ${RoundNo}`,50,10);
textStyle(NORMAL)
// User
textSize(12);
fill('#9C27B0')
textStyle(BOLD)
text( `👤 ${user_name}`,WIN_WIDTH-4*(user_name.length+3),10);
textStyle(NORMAL)
//logout button position
if(player_round_scores[RoundNo]!=-2){
textSize(15);
textStyle(BOLD);
text(`🙎🏻♂️ score for the round`,APP_WIDTH/4,3*WIN_HEIGHT/4 +5*H10);
textStyle(NORMAL);
text(`${player_round_scores[RoundNo]}`,APP_WIDTH/4,3*WIN_HEIGHT/4 +7*H10);
}
if(agent_round_scores[RoundNo]!=-2){
textSize(15);
textStyle(BOLD);
text(`🤖 score for the round`,APP_WIDTH/2+APP_WIDTH/4,3*WIN_HEIGHT/4 +5*H10);
textStyle(NORMAL);
text(`${agent_round_scores[RoundNo]}`,APP_WIDTH/2+APP_WIDTH/4,3*WIN_HEIGHT/4 +7*H10);
}
//play next round
if(gameOver && !all_rounds_over){
fill('#6495ED');
rect(APP_WIDTH/3+10,WIN_HEIGHT-8*H10,22*H10,3*W10,15);
textSize(15);
fill('black');
text('Click here to play next round!',APP_WIDTH/3+8*W10,WIN_HEIGHT-6*H10)
}
}
//APP_WIDTH/3+10,WIN_HEIGHT-8*H10,22*H10,3*W10
function mousePressed(){
if(RoundNo<TotalRounds && gameOver && mouseX>APP_WIDTH/3+10 && mouseX<APP_WIDTH/3+10+22*H10 && mouseY>WIN_HEIGHT-8*H10 && mouseY< WIN_HEIGHT-8*H10+3*W10){
gameOver=false;
mid_setup();
RoundNo++;
}
return;
}
function bidChange(){
lock_error="";
switch(this.html()) {
case '➖1':
if(playerTokens<maxTokens && playerCurrentBid>0 && !gameOver && !lock_bid){
playerCurrentBid--;
playerTokens++;
}
won_or_not="";
break;
case '➕1':
if(playerTokens>0 && playerCurrentBid<maxTokens &&!gameOver && !lock_bid){
playerCurrentBid++;
playerTokens--;
}
won_or_not="";
break;
case '➖2':
if(playerTokens<maxTokens && playerCurrentBid>1 && !gameOver && !lock_bid){
playerCurrentBid-=2;
playerTokens+=2;
}
won_or_not="";
break;
case '➕2':
if(playerTokens>1 && playerCurrentBid<maxTokens &&!gameOver && !lock_bid){
playerCurrentBid+=2;
playerTokens-=2;
}
won_or_not="";
break;
case '➖5':
if(playerTokens<maxTokens && playerCurrentBid>4 && !gameOver && !lock_bid){
playerCurrentBid-=5;
playerTokens+=5;
}
won_or_not="";
break;
case '➕5':
if(playerTokens>4 && playerCurrentBid<maxTokens &&!gameOver && !lock_bid){
playerCurrentBid+=5;
playerTokens-=5;
}
won_or_not="";
break;
default:
won_or_not="";
}
return;
}
function go(){
if(!gameOver){
// playerTokens -= playerCurrentBid;
if(playerCurrentBid>0 ){
if (playerCurrentBid > agentCurrentBid){
player_auctioned_digits.push(digits[digits_to_auction[digits_to_auction.length-1]]);
player_auctioned_digits_raw.push(digits_to_auction[digits_to_auction.length-1]);
won_or_not = `🙎🏻♂️ won ${digits[digits_to_auction[digits_to_auction.length-1]]}`
digits_to_auction.pop();
}
else if(playerCurrentBid < agentCurrentBid) {
agent_auctioned_digits.push(digits[digits_to_auction[digits_to_auction.length-1]]);
agent_auctioned_digits_raw.push(digits_to_auction[digits_to_auction.length-1]);
won_or_not = `🤖 won ${digits[digits_to_auction[digits_to_auction.length-1]]}`
digits_to_auction.pop();
}
else{
won_or_not = `Draw! Bid again for ${digits[digits_to_auction[digits_to_auction.length-1]]}`
playerTokens += playerCurrentBid;
agentTokens += agentCurrentBid;
}
lock_bid_btn.html("🔓");
lock_bid=false;
go_button.hide();
playerCurrentBid=0;
agentCurrentBid=0;
select_index_label="";
if((playerTokens == 0 )||(agentTokens == 0 )||(digits_to_auction.length==0)){
gameOver=true;
if (playerTokens==0){
for(let n=1;n<=min(agentTokens,digits_to_auction.length);n++){
agent_auctioned_digits.push(digits[digits_to_auction[digits_to_auction.length-n]]);
agent_auctioned_digits_raw.push(digits_to_auction[digits_to_auction.length-n]);
}
agentTokens -= min(agentTokens,digits_to_auction.length);
}
else if (agentTokens == 0){
for(let n=1;n<=min(playerTokens,digits_to_auction.length);n++){
player_auctioned_digits.push(digits[digits_to_auction[digits_to_auction.length-n]]);
player_auctioned_digits_raw.push(digits_to_auction[digits_to_auction.length-n]);
}
playerTokens -= min(playerTokens,digits_to_auction.length);
}
if(int( player_auctioned_digits_raw.join('')) > int( agent_auctioned_digits_raw.join(''))){
player_win_status[RoundNo]='✅';
player_wins+=1;
agent_loses+=1;
}
else{
agent_win_status[RoundNo]='✅';
agent_wins+=1;
player_loses+=1;
}
if(RoundNo == TotalRounds){
all_rounds_over=true;
select_index_label="All Rounds are Over!.Thank you 🙏🏻";
if(player_wins>agent_wins){
player_cup='🏆';
}else if(agent_wins>player_wins){
agent_cup = '🏆';
}
}
else{
select_index_label=`Round ${RoundNo} is Over!`;
}
player_auctioned_digits_raw.sort((a,b) => b-a);
if(player_auctioned_digits_raw.length==0){
player_round_scores[RoundNo]=-1;
}
else{
player_round_scores[RoundNo]=int(player_auctioned_digits_raw.join(""));
}
let player_final_digits = player_auctioned_digits_raw.map(x=>digits[x]);
player_final_number = player_auctioned_digits_raw.map(x=>digits[x]).join("");
agent_auctioned_digits_raw.sort((a,b) => b-a);
if(agent_auctioned_digits_raw.length==0){
agent_round_scores[RoundNo]=-1;
}
else{
agent_round_scores[RoundNo]=int(agent_auctioned_digits_raw.join(""));
}
let agent_final_digits = agent_auctioned_digits_raw.map(x=>digits[x]);
agent_final_number = agent_auctioned_digits_raw.map(x=>digits[x]).join("");
sendData();
}
}
}
}
//google sheet where user_name, score etc will be stored
let url = "https://script.google.com/macros/s/AKfycbxTUkw_NPwNkPEItaNYULcr_Y2VW6zkTOtpHJ9X-t0LLGVpK1G_Uz-Ny3_bai3ks7g/exec";
function sendData() {
let data = {
joiningCode:joining_code,
username: user_name,
roundNo:RoundNo,
score: player_round_scores[RoundNo]
};
fetch(url, {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
}).then(() => console.log("Data Sent"));
}