Example #1
0
    def test_openings(self):
        openings = dominioncards.opening_cards()
        self.assertEquals(len(openings), 140)

        # Valid opening cards

        # Cost 0
        self.assertIn(dominioncards.Copper, openings)

        # Cost 2
        self.assertIn(dominioncards.Chapel, openings)

        # Cost 3
        self.assertIn(dominioncards.Ambassador, openings)

        # Cost 4
        self.assertIn(dominioncards.Baron, openings)

        # Cost 5
        self.assertIn(dominioncards.Bazaar, openings)

        # Non-openings

        # Requires a potion, can't be an opening
        self.assertNotIn(dominioncards.Alchemist, openings)

        # Too expensive
        self.assertNotIn(dominioncards.Bank, openings)
Example #2
0
    def test_openings(self):
        openings = dominioncards.opening_cards()
        self.assertEquals(len(openings), 140)

        # Valid opening cards

        # Cost 0
        self.assertIn(dominioncards.Copper, openings)

        # Cost 2
        self.assertIn(dominioncards.Chapel, openings)

        # Cost 3
        self.assertIn(dominioncards.Ambassador, openings)

        # Cost 4
        self.assertIn(dominioncards.Baron, openings)

        # Cost 5
        self.assertIn(dominioncards.Bazaar, openings)


        # Non-openings

        # Requires a potion, can't be an opening
        self.assertNotIn(dominioncards.Alchemist, openings)

        # Too expensive
        self.assertNotIn(dominioncards.Bank, openings)
Example #3
0
    def GET(self):
        web.header("Content-Type", "text/html; charset=utf-8")  
        query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
        db = utils.get_mongo_database()
        selected_card = ''

        if 'card' in query_dict:
            selected_card = query_dict['card']

        results = db.trueskill_openings.find({'_id': {'$regex': '^open:'}})
        openings = list(results)
        card_list = dominioncards.opening_cards()
        def split_opening(o):
            ret = o['_id'][len('open:'):].split('+')
            if ret == ['']: return []

            # Convert the __repr__() representation stored in the
            # database to the singular version of the card name.
            return [dominioncards.get_card(card).singular for card in ret]

        if selected_card not in ('All cards', ''):
            openings = [o for o in openings if selected_card in 
                        split_opening(o)]
                        
        openings = [o for o in openings if split_opening(o)]
        for opening in openings:
            floor = opening['mu'] - opening['sigma'] * 3
            ceil = opening['mu'] + opening['sigma'] * 3
            opening['level_key'] = make_level_key(floor, ceil)
            opening['level_str'] = make_level_str(floor, ceil)
            opening['skill_str'] = skill_str(opening['mu'], opening['sigma'])
            opening['cards'] = split_opening(opening)
            opening['cards'].sort()
            opening['cards'].sort(key=lambda card: dominioncards.get_card(card).cost, reverse=True)
            costs = [str(dominioncards.get_card(card).cost) for card in opening['cards']]
            while len(costs) < 2:
                costs.append('-')
            opening['cost'] = '/'.join(costs)

        openings.sort(key=lambda opening: opening['level_key'])
        openings.reverse()
        if selected_card == '':
            openings = [op for op in openings
                        if op['level_key'][0] != 0
                        or op['_id'] == ['Silver', 'Silver']]

        render = web.template.render('')
        return render.openings_template(openings, card_list, selected_card)
Example #4
0
    def GET(self):
        web.header("Content-Type", "text/html; charset=utf-8")  
        query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
        db = utils.get_mongo_database()
        selected_card = ''

        if 'card' in query_dict:
            selected_card = query_dict['card']

        results = db.trueskill_openings.find({'_id': {'$regex': '^open:'}})
        openings = list(results)
        card_list = dominioncards.opening_cards()
        def split_opening(o):
            ret = o['_id'][len('open:'):].split('+')
            if ret == ['']: return []

            # Convert the __repr__() representation stored in the
            # database to the singular version of the card name.
            return [dominioncards.get_card(card).singular for card in ret]

        if selected_card not in ('All cards', ''):
            openings = [o for o in openings if selected_card in 
                        split_opening(o)]
                        
        openings = [o for o in openings if split_opening(o)]
        for opening in openings:
            floor = opening['mu'] - opening['sigma'] * 3
            ceil = opening['mu'] + opening['sigma'] * 3
            opening['level_key'] = make_level_key(floor, ceil)
            opening['level_str'] = make_level_str(floor, ceil)
            opening['skill_str'] = skill_str(opening['mu'], opening['sigma'])
            opening['cards'] = split_opening(opening)
            opening['cards'].sort()
            opening['cards'].sort(key=lambda card: dominioncards.get_card(card).cost, reverse=True)
            costs = [str(dominioncards.get_card(card).cost) for card in opening['cards']]
            while len(costs) < 2:
                costs.append('-')
            opening['cost'] = '/'.join(costs)

        openings.sort(key=lambda opening: opening['level_key'])
        openings.reverse()
        if selected_card == '':
            openings = [op for op in openings
                        if op['level_key'][0] != 0
                        or op['_id'] == ['Silver', 'Silver']]

        render = web.template.render('')
        return render.openings_template(openings, card_list, selected_card)
    def test_openings(self):
        openings = dominioncards.opening_cards()
        self.assertEquals(len(openings), 189)

        # Valid opening cards

        # Cost 0
        self.assertIn(dominioncards.Copper, openings)

        # Cost 1
        self.assertIn(dominioncards.PoorHouse, openings)

        # Cost 2
        self.assertIn(dominioncards.Squire, openings)

        # Cost 3
        self.assertIn(dominioncards.Ambassador, openings)

        # Cost 4
        self.assertIn(dominioncards.Baron, openings)

        # Cost 5
        self.assertIn(dominioncards.Bazaar, openings)


        # Non-openings

        # Requires a potion, can't be an opening
        self.assertNotIn(dominioncards.Alchemist, openings)

        # Too expensive
        self.assertNotIn(dominioncards.Bank, openings)

        # Not in supply
        self.assertNotIn(dominioncards.Hovel, openings)
        self.assertNotIn(dominioncards.Spoils, openings)