How can one describe a rock-paper-scissors relationship between 3 items?

后端 未结 3 1211
深忆病人
深忆病人 2021-01-04 09:19

Let\'s say I have the following structure:

abstract class Hand {}

class Rock extends Hand {}
class Paper extends Hand {}
class Scissors extends Hand {}
         


        
3条回答
  •  感情败类
    2021-01-04 10:13

    From PHP chat

    OOP-style

    Simple function

     ROCK, ROCK => SCISSORS, SCISSORS => PAPER];
        return intval($winners[$hand1] !== $hand2) + 1;
    }
    

提交回复
热议问题