View the step-by-step solution to:

Question

I NEED HELP ASAP!


so i wrote a code that does the following: it asks the user for 8 inputs,

each input they have to put 8 characters, (K)ing, (Q)ueen, (B)ishop, k(N)ight, (R)ook, and (P)awn (Example of one input: "-----k--". after this the program outputs the points of white and black and tells us who is winning, using the relative value system. (capital letters represent Black pieces, and lower case letters represent White pieces.


example:


Please type 8 characters for the 1th row of chessboard ::-----k--

Please type 8 characters for the 2th row of chessboard ::--------

Please type 8 characters for the 3th row of chessboard ::---n----

Please type 8 characters for the 4th row of chessboard ::--------

Please type 8 characters for the 5th row of chessboard ::--------

Please type 8 characters for the 6th row of chessboard ::----K---

Please type 8 characters for the 7th row of chessboard ::--------

Please type 8 characters for the 8th row of chessboard ::---Q----

Black Score :: 3  White Score ::10

White is currently winning!


I want to know how to code the following: if the user wishes to move pieces on the chessboard, how can i make a code that edits the list according to what the user wants and then outputs once again who is winning.


i will attach my code for reference:


#dictionary for values


values = {'k':0, 'q':10, 'b':3, 'r':5, 'n':3, 'p':1, '-':0};


#function for user input board validating


def userInput():


  global data


  data=[]


        #reading the user iunput


  for x in range(1,9):


    temp = input("Please type 8 characters for the "+str(x)+"th row of chessboard ::")


     

    data = data + list(temp)

     


#validating the board


  result = validate(data)

   

  #printing the result

  print(result)


        


        #end of function


#function to validate the board


def validate(data):


        #score variables


  white_score=0


  black_score=0


        #calculating the scores


  for piece in data:


    if(piece.isalpha()):


       


                        #adding the scores


      if(piece.isupper()):


        white_score = white_score + values[piece.lower()]


      else:


        black_score = black_score + values[piece.lower()]


                                


        #result formation


  output = "Black Score :: "+str(black_score)+"  White Score ::"+str(white_score)


        #winner evaluation


  if(black_score>white_score):


    output=output+"nBlack is currently winning!"


  elif(black_score<white_score):


    output=output+"nWhite is currently winning!"


  else:


    output=output+"nGame is currently a tie!"


                


        #returnig the output


  return output


        #end of function

def userContinue():


  continue1 = True

  while(continue1):


    print()

    print("Type 'new' to start a new chessboard")

    print("Type 'move' to move a piece")

    print("Type 'QUIT' to end program")

    print()


    nextStep = input("Enter: ")

    if nextStep == "new":

      userInput()

      userContinue()


    elif nextStep == "move":

      print()

      print("Your current chessboard:: ")

      print(data)

       

    elif nextStep == "QUIT":

      print("You chose to end the game, bye!")

      continue1 = False



#main function to run program


userInput()

userContinue()

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes