Deck
Represents a deck of Flesh and Blood cards.
Attributes:
Name | Type | Description |
---|---|---|
cards |
CardList
|
The "main" part of the deck from which one draws cards. |
format |
str
|
The game format code associated with the deck (see |
hero |
Card
|
The hero card associated with the deck. |
inventory |
CardList
|
The list of weapon/equipment cards associated with the deck (not including items). |
name |
str
|
An arbitrary name for the deck. |
notes |
Optional[str]
|
Any additional notes to include about the deck, in Markdown format. |
tokens |
CardList
|
Any token cards associated with the deck. |
Source code in fab/deck.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
|
__getitem__(index)
¶
Allows one to access cards form the "main" part of the deck using index notation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index |
int | slice
|
An |
required |
Returns:
Type | Description |
---|---|
Card | CardList
|
A particular |
Source code in fab/deck.py
86 87 88 89 90 91 92 93 94 95 96 97 |
|
__iter__()
¶
Iterator implementation over the "main" part of the deck.
Source code in fab/deck.py
99 100 101 102 103 |
|
__len__()
¶
Returns the total number of cards within this deck, excluding tokens or the hero.
Returns:
Type | Description |
---|---|
int
|
The number of "main" deck and inventory cards. |
Source code in fab/deck.py
105 106 107 108 109 110 111 112 113 |
|
all_cards(include_tokens=False)
¶
Returns all cards within this deck (excluding tokens by default).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_tokens |
bool
|
Whether to include token cards in the result. |
False
|
Returns:
Type | Description |
---|---|
CardList
|
A single |
Source code in fab/deck.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
auto_build(cards, catalog=None, honor_counts=False, max_generic_count=None, only_legal=True, replace=True, target_deck_size=None, target_inventory_size=None, target_pitch_cost_difference=None, target_power_defense_difference=None)
¶
Automatically populates this deck with cards based on its hero, by selecting cards from the specified list.
This method updates the Deck
object calling it directly, rather than
returning any object. Cards are mostly chosen at random, however it will
ensure that you have at least one card for each inventory slot and meet
all of the count/type requirements for the deck. Any cards that mention
a token by name will have that token included.
For the target_pitch_cost_difference
and
target_power_defense_difference
arguments, randomly selected cards
will be discarded if they push the relevant statistic away from the
target value (if not None
). When selecting a value for cost-pitch, you
may want to refer to the following formula:
target = 0
+ {total additional cost from card body texts}
+ {total cost of using equipment}
+ ({number of times you plan on using weapon} * {cost of using weapon})
+ ({number of times you plan on using hero ability} * {cost of hero ability})
- {additional resource points generated from card body texts}
Of course the above formula isn't perfect, but you should get the general idea. In theory, a perfectly balanced deck should expect to generate the minimum number of resources for their typical combos every turn. Currently, this method will "give up" attempting to meet these targets after 100 tries and will accept a random card before resuming attempts.
Note
To be able to accurately compare cards, a card catalog
must be
provided, defaulting to the global catalog card.CARD_CATALOG
if
unspecified.
This method ignores the current legality of the deck's hero.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cards |
CardList
|
The input list of cards from which to choose from. |
required |
catalog |
Optional[CardList]
|
An optional |
None
|
honor_counts |
bool
|
Whether to honor the number of copies of each card in the specified input list. |
False
|
max_generic_count |
Optional[int]
|
Overrides the maximum number of generic cards to include in the main deck, defaulting to at most 20% of the deck. |
None
|
only_legal |
bool
|
Whether to only select cards that are currently legal (not banned, suspended, or living legend). |
True
|
replace |
bool
|
Whether to replace cards that may already exist within the deck. |
True
|
target_deck_size |
Optional[int]
|
Overrides the target number of cards to include in the main deck. |
None
|
target_inventory_size |
Optional[int]
|
Overrides the target number of cards to include in the deck's inventory. |
None
|
target_pitch_cost_difference |
Optional[int]
|
Specifies the target pitch-cost difference of the main deck, or |
None
|
target_power_defense_difference |
Optional[int]
|
Specifies the target power-defense difference of the main deck, or |
None
|
Source code in fab/deck.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
filter_related(cards, catalog=None, include_generic=True, only_legal=True)
¶
Filters out cards from the specified list which may be included in this deck, based on the deck's hero card.
Warning
This method does not validate the legality of the deck's hero card.
Note
To be able to accurately compare cards, a card catalog
must be
provided, defaulting to the global catalog card.CARD_CATALOG
if
unspecified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cards |
CardList
|
The list of cards to filter. |
required |
catalog |
Optional[CardList]
|
An optional |
None
|
include_generic |
bool
|
Whether to include Generic cards in the result. |
True
|
only_legal |
bool
|
Whether to include only cards that are currently legal (not banned, suspended, or living legend). |
True
|
Returns:
Type | Description |
---|---|
CardList
|
A subset of the specified card list that work with the deck's hero. |
Source code in fab/deck.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
from_deck_list(name, deck_list, catalog=None, format='B', notes=None)
staticmethod
¶
Constructs a deck from the given deck list dictionary, where keys correspond to the full name of a card and values are their counts.
Note
To be able to generate cards, a card catalog
must be provided,
defaulting to the global catalog card.CARD_CATALOG
if unspecified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The arbitrary name for the new |
required |
deck_list |
dict[str, int]
|
The deck list to create the |
required |
catalog |
Optional[CardList]
|
An optional |
None
|
format |
str
|
The game format of the deck, being any valid |
'B'
|
notes |
Optional[str]
|
Any additional notes to include with the deck, in Markdown format. |
None
|
Returns:
Type | Description |
---|---|
Deck
|
A new |
Source code in fab/deck.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
|
from_fabdb(url, catalog=None)
staticmethod
¶
Imports a deck from FaB DB.
Decks may be imported by providing either their full URL
(https://fabdb.net/decks/VGkQMojg
) or unique identifier (VGkQMojg
).
Note
To be able to generate cards, a card catalog
must be provided,
defaulting to the global catalog card.CARD_CATALOG
if unspecified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
catalog |
Optional[CardList]
|
An optional |
None
|
url |
str
|
The full URL or unique identifier of the deck to import. |
required |
Returns:
Type | Description |
---|---|
Deck
|
The imported |
Source code in fab/deck.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
|
from_json(jsonstr)
staticmethod
¶
Parses a new deck from a given JSON string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
jsonstr |
str
|
The JSON string representation to parse. |
required |
Returns:
Type | Description |
---|---|
Deck
|
A new |
Source code in fab/deck.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
|
is_valid(ignore_copy_limits=False, ignore_hero_legality=False, ignore_inv_size_limits=False, ignore_legality=False, ignore_size_limits=False)
¶
Returns whether this is a valid and legal deck given its format.
Unless otherwise specified, in general this method ensures:
- The deck contains at least one hero, inventory card, and main deck card.
- The deck has a valid game format code.
- The deck doesn't have any invalid card placements (like inventory cards in the main deck).
- All cards (including hero) are currently legal for play.
- Main deck and inventory deck sizes conform to the specified format.
- The deck doesn't contain too many copies of a particular card (according to the specified format).
- The deck only contains cards which adhere to the specified format's rarity requirements.
Warning
This function currently does not validate any restrictions printed on cards themselves (ex: "Legendary" cards). Also, any restrictions on card rarity might not be accurate, since cards may be printed in multiple rarities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ignore_copy_limits |
bool
|
Whether to ignore limits around the allowed number of card copies. |
False
|
ignore_hero_legality |
bool
|
Whether to ignore the current legal status of the hero card. |
False
|
ignore_inv_size_limits |
bool
|
Whether to ignore any maximum/minimum inventory deck size limits. |
False
|
ignore_legality |
bool
|
Whether to ignore the current legal status of cards (not including the hero). |
False
|
ignore_size_limits |
bool
|
Whether to ignore any maximum/minimum size limits of the main deck. |
False
|
Returns:
Type | Description |
---|---|
tuple[bool, Optional[str]]
|
A |
Source code in fab/deck.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
load(file_path, name=None, format=None)
staticmethod
¶
Loads a deck from the specified JSON or TXT file.
Note
When loading from a TXT file, the name and format of the deck must be specified. TXT files loaded by this method expect a file with entries of the following form separated by new lines:
{count} {full_name}
where count
is the number of copies of the specified card and
full_name
is the full name of the card (see Card.full_name
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The file path from which to load. |
required |
name |
Optional[str]
|
The name of the resulting deck, if loading from TXT file. |
None
|
format |
Optional[str]
|
The format code of the resulting deck, if loading from TXT file. |
None
|
Returns:
Type | Description |
---|---|
Deck
|
A new |
Source code in fab/deck.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
|
render_notes()
¶
Renders the notes of this deck as a Markdown cell.
Returns:
Type | Description |
---|---|
Any
|
The IPython-rendered markdown output. |
Source code in fab/deck.py
557 558 559 560 561 562 563 564 565 566 567 |
|
save(file_path)
¶
Saves this deck to the specified JSON or TXT file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The file path to save to. |
required |
Source code in fab/deck.py
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
|
search_fabdb(hero, cursor=None, format='B', kind='competitive', max_results=30, order='popular-all')
staticmethod
¶
Searches FaB DB for decks matching the specified constraints.
The result of this method is a dict
containing two primary keys:
cursor
- Astr
which may be re-passed to the method (along with the same set of other arguments) to retrieve the "next page" of results.decks
- Alist
of deck specifications.
Each deck specification is also a dict
containing the following keys:
creator
- The FaB DB user name of the deck creator.format
- The game format associated with the deck.gem_id
- The Gem ID of the deck creator (if available).hero
- The full name of the hero.id
- The ID of the deck, as would be passed toDeck.from_fabdb()
.kind
- The kind of deck.name
- The name of the deck.notes
- Any notes associated with the deck (in markdown format).url
- The full URL corresponding to the deck.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cursor |
Optional[str]
|
An optional cursor string for iterating through multi-page responses. |
None
|
format |
str
|
The game format identifier (as would be specified for |
'B'
|
hero |
Card | str
|
A |
required |
kind |
Optional[str]
|
The type of deck to search for ( |
'competitive'
|
max_results |
int
|
The maximum number of results to include in the response. |
30
|
order |
str
|
The method by which to order search results ( |
'popular-all'
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
The results of the search. |
Source code in fab/deck.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 |
|
statistics(precision=2)
¶
Computes useful statistics associated with this deck, returning the following keys:
card_statistics
-CardList.statistics()
on the "main" deck of cards, with health and intelligence metrics removed.hero
- Contains the intelligence and health of the deck's hero.inventory_statistics
-CardList.statistics()
on the inventory cards, with health, intelligence, cost, and pitch metrics removed since they aren't applicable.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A |
Source code in fab/deck.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
|
to_deck_list(include_tokens=False)
¶
Returns a deck-list dictionary for this deck.
The keys of this dictionary correspond to the full names (including pitch value) of cards, while the values are their corresponding counts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_tokens |
bool
|
Whether to include token cards in the deck list. |
False
|
Returns:
Type | Description |
---|---|
dict[str, int]
|
The deck-list representation of the deck. |
Source code in fab/deck.py
676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
|
to_dict()
¶
Returns the raw dictionary form of the deck.
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A raw |
Source code in fab/deck.py
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
|
to_json()
¶
Returns the JSON string representation of the deck.
Returns:
Type | Description |
---|---|
str
|
The JSON string representation of the deck. |
Source code in fab/deck.py
708 709 710 711 712 713 714 715 |
|
valid_types(include_generic=True)
¶
Returns the set of valid card types which may be included in this deck, based on the deck's hero card.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_generic |
bool
|
Whether to include the Generic type in the result. |
True
|
Returns:
Type | Description |
---|---|
list[str]
|
A |
Source code in fab/deck.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
|