示例#1
0
class Game:
    def __init__(self,ball_stack):
        self.ball_container=ball_stack
        self.red_balls_container=Stack(2)
        self.green_balls_container = Stack(2)
        self.blue_balls_container = Stack(2)
        self.yellow_balls_container = Stack(2)
    def grouping_based_on_color(self):
        for i in range(0,self.ball_container.get_max_size()):
            a = self.ball_container.pop()
            if(a.get_color()=="Red"):
                self.red_balls_container.push(a)
            elif(a.get_color()=="Blue"):
                self.blue_balls_container.push(a)
            elif(a.get_color()=="Yellow"):
                self.yellow_balls_container.push(a)
            elif(a.get_color()=="Green"):
                self.green_balls_container.push(a)
    def rearrange_balls(self,color):
        if(color=="Red"):
            for x in range (2):
                ball =self.red_balls_container.pop()
                if(ball.get_name()=="A"):
                    a = ball
                else:
                    b = ball
            self.red_balls_container.push(b)
            self.red_balls_container.push(a)
        elif(color == "Blue"):
            for x in range (2):
                ball =self.blue_balls_container.pop()
                if(ball.get_name()=="A"):
                    a = ball
                else:
                    b = ball
            self.blue_balls_container.push(b)
            self.blue_balls_container.push(a)
    def display_ball_details(self,color):
        pass
示例#2
0
def separate_boxes(box_stack):
    #Remove pass and write your logic here
    new_queue = Queue(box_stack.get_max_size())
    mod_stack = Stack(box_stack.get_max_size())
    while (not (box_stack.is_empty())):
        data = box_stack.pop()
        if (data == "Red" or data == "Green" or data == "Blue"):
            mod_stack.push(data)
        else:
            new_queue.enqueue(data)
    while (not (mod_stack.is_empty())):
        a = mod_stack.pop()
        box_stack.push(a)
    return (new_queue)
示例#3
0
class Game:
    def __init__(self, ball_stack):
        self.ball_container = ball_stack
        self.red_balls_container = Stack(4)
        self.green_balls_container = Stack(4)
        self.blue_balls_container = Stack(4)
        self.yellow_balls_container = Stack(4)

    def grouping_based_on_color(self):
        while (not (self.ball_container.is_empty())):
            a = self.ball_container.pop()
            if (a.get_color() == "Red"):
                self.red_balls_container.push(a)
            elif (a.get_color() == "Green"):
                self.green_balls_container.push(a)

            elif (a.get_color() == "Yellow"):
                self.yellow_balls_container.push(a)

            elif (a.get_color() == "Blue"):
                self.blue_balls_container.push(a)

    def rearrange_balls(self, color):

        if (color == "Red"):
            list1 = []
            list2 = []
            while (not (self.red_balls_container.is_empty())):
                a = self.red_balls_container.pop()
                if (a.get_name() == "B"):
                    list1.append(a)
                else:
                    list2.append(a)
            for i in list1:
                self.red_balls_container.push(i)
            for j in list2:
                self.red_balls_container.push(j)

        elif (color == "Green"):
            list1 = []
            list2 = []
            while (not (self.green_balls_container.is_empty())):
                a = self.green_balls_container.pop()
                if (a.get_name() == "B"):
                    list1.append(a)
                else:
                    list2.append(a)
            for i in list1:
                self.green_balls_container.push(i)
            for j in list2:
                self.green_balls_container.push(j)
        elif (color == "Blue"):
            list1 = []
            list2 = []
            while (not (self.blue_balls_container.is_empty())):
                a = self.blue_balls_container.pop()
                if (a.get_name() == "B"):
                    list1.append(a)
                else:
                    list2.append(a)
            for i in list1:
                self.blue_balls_container.push(i)
            for j in list2:
                self.blue_balls_container.push(j)
        elif (color == "Yellow"):
            list1 = []
            list2 = []
            while (not (self.yellow_balls_container.is_empty())):
                a = self.yellow_balls_container.pop()
                if (a.get_name() == "B"):
                    list1.append(a)
                else:
                    list2.append(a)
            for i in list1:
                self.yellow_balls_container.push(i)
            for j in list2:
                self.yellow_balls_container.push(j)

    def display_ball_details(self, color):
        pass