0

I am making chess engine as a project I noticed that I had to use a lot of if statments because of that code was hard to read I came up with this solution for example when changing turns instead of writing

if(turn=="white"){
    turn="black"
}else{
    turn="white"
}

I did this

const switchTurns={
   "white":"black",
   "black":"white"   
}
turn=switchTurns[turn]

it looks like I am making my job harder with this objects but it helped a lot when I had to check way more things to get value like pisce, pisce index,is it middlegame or not and change tham based on other stuff I am 17year old I learned on my own and I don't know exactly how everything works behind programming languages I am wondering does this method makes program slower or it is same? also is this good practice or not and why? thanks in advance

ne0123.
  • 9
  • 3

0 Answers0