Worked on goal action

This commit is contained in:
Lukas Wölfer
2020-02-13 01:17:42 +01:00
parent 2dca549f21
commit 45b7ed22ba
3 changed files with 92 additions and 19 deletions

View File

@@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages] [dev-packages]
mypy = "*" mypy = "*"
black = "*" black = "*"
pylint = "*"
[packages] [packages]
pyautogui = "*" pyautogui = "*"

70
Pipfile.lock generated
View File

@@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "fa4a7a5c49ad466a4a7ae75d530e60ef7868f6f7e8619d2e6306952065482656" "sha256": "055fd8f6179875deb64739938a271e0ba8c49daee4696baf3c7a36f723e81573"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@@ -167,6 +167,13 @@
], ],
"version": "==1.4.3" "version": "==1.4.3"
}, },
"astroid": {
"hashes": [
"sha256:71ea07f44df9568a75d0f354c49143a4575d90645e9fead6dfb52c26a85ed13a",
"sha256:840947ebfa8b58f318d42301cf8c0a20fd794a33b61cc4638e28e9e61ba32f42"
],
"version": "==2.3.3"
},
"attrs": { "attrs": {
"hashes": [ "hashes": [
"sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c", "sha256:08a96c641c3a74e44eb59afb61a24f2cb9f4d7188748e76ba4bb5edfa3cb7d1c",
@@ -189,6 +196,46 @@
], ],
"version": "==7.0" "version": "==7.0"
}, },
"isort": {
"hashes": [
"sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1",
"sha256:6e811fcb295968434526407adb8796944f1988c5b65e8139058f2014cbe100fd"
],
"version": "==4.3.21"
},
"lazy-object-proxy": {
"hashes": [
"sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d",
"sha256:194d092e6f246b906e8f70884e620e459fc54db3259e60cf69a4d66c3fda3449",
"sha256:1be7e4c9f96948003609aa6c974ae59830a6baecc5376c25c92d7d697e684c08",
"sha256:4677f594e474c91da97f489fea5b7daa17b5517190899cf213697e48d3902f5a",
"sha256:48dab84ebd4831077b150572aec802f303117c8cc5c871e182447281ebf3ac50",
"sha256:5541cada25cd173702dbd99f8e22434105456314462326f06dba3e180f203dfd",
"sha256:59f79fef100b09564bc2df42ea2d8d21a64fdcda64979c0fa3db7bdaabaf6239",
"sha256:8d859b89baf8ef7f8bc6b00aa20316483d67f0b1cbf422f5b4dc56701c8f2ffb",
"sha256:9254f4358b9b541e3441b007a0ea0764b9d056afdeafc1a5569eee1cc6c1b9ea",
"sha256:9651375199045a358eb6741df3e02a651e0330be090b3bc79f6d0de31a80ec3e",
"sha256:97bb5884f6f1cdce0099f86b907aa41c970c3c672ac8b9c8352789e103cf3156",
"sha256:9b15f3f4c0f35727d3a0fba4b770b3c4ebbb1fa907dbcc046a1d2799f3edd142",
"sha256:a2238e9d1bb71a56cd710611a1614d1194dc10a175c1e08d75e1a7bcc250d442",
"sha256:a6ae12d08c0bf9909ce12385803a543bfe99b95fe01e752536a60af2b7797c62",
"sha256:ca0a928a3ddbc5725be2dd1cf895ec0a254798915fb3a36af0964a0a4149e3db",
"sha256:cb2c7c57005a6804ab66f106ceb8482da55f5314b7fcb06551db1edae4ad1531",
"sha256:d74bb8693bf9cf75ac3b47a54d716bbb1a92648d5f781fc799347cfc95952383",
"sha256:d945239a5639b3ff35b70a88c5f2f491913eb94871780ebfabb2568bd58afc5a",
"sha256:eba7011090323c1dadf18b3b689845fd96a61ba0a1dfbd7f24b921398affc357",
"sha256:efa1909120ce98bbb3777e8b6f92237f5d5c8ea6758efea36a473e1d38f7d3e4",
"sha256:f3900e8a5de27447acbf900b4750b0ddfd7ec1ea7fbaf11dfa911141bc522af0"
],
"version": "==1.4.3"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
"version": "==0.6.1"
},
"mypy": { "mypy": {
"hashes": [ "hashes": [
"sha256:0a9a45157e532da06fe56adcfef8a74629566b607fa2c1ac0122d1ff995c748a", "sha256:0a9a45157e532da06fe56adcfef8a74629566b607fa2c1ac0122d1ff995c748a",
@@ -223,6 +270,14 @@
], ],
"version": "==0.7.0" "version": "==0.7.0"
}, },
"pylint": {
"hashes": [
"sha256:3db5468ad013380e987410a8d6956226963aed94ecb5f9d3a28acca6d9ac36cd",
"sha256:886e6afc935ea2590b462664b161ca9a5e40168ea99e5300935f6591ad467df4"
],
"index": "pypi",
"version": "==2.4.4"
},
"regex": { "regex": {
"hashes": [ "hashes": [
"sha256:07b39bf943d3d2fe63d46281d8504f8df0ff3fe4c57e13d1656737950e53e525", "sha256:07b39bf943d3d2fe63d46281d8504f8df0ff3fe4c57e13d1656737950e53e525",
@@ -249,6 +304,13 @@
], ],
"version": "==2020.1.8" "version": "==2020.1.8"
}, },
"six": {
"hashes": [
"sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a",
"sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c"
],
"version": "==1.14.0"
},
"toml": { "toml": {
"hashes": [ "hashes": [
"sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c",
@@ -289,6 +351,12 @@
"sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575" "sha256:cf8b63fedea4d89bab840ecbb93e75578af28f76f66c35889bd7065f5af88575"
], ],
"version": "==3.7.4.1" "version": "==3.7.4.1"
},
"wrapt": {
"hashes": [
"sha256:565a021fd19419476b9362b05eeaa094178de64f8361e44468f9e9d7843901e1"
],
"version": "==1.11.2"
} }
} }
} }

View File

@@ -1,5 +1,4 @@
"""Contains function to iterate different kinds of possible actions""" """Contains function to iterate different kinds of possible actions"""
import pdb
from typing import Iterator, List, Tuple from typing import Iterator, List, Tuple
from .. import board from .. import board
@@ -116,33 +115,38 @@ def possible_goal_move_actions(
(board.Position.Field, index, stack[-1]) (board.Position.Field, index, stack[-1])
for index, stack in enumerate(search_board.field) for index, stack in enumerate(search_board.field)
if stack if stack
if isinstance(stack[-1], board.NumberCard)
] ]
bunker_cards = [ bunker_cards = [
(board.Position.Bunker, index, card) (board.Position.Bunker, index, card)
for index, card in enumerate(search_board.bunker) for index, card in enumerate(search_board.bunker)
if isinstance(card, board.NumberCard)
] ]
top_cards = field_cards + bunker_cards top_cards = [
x for x in field_cards + bunker_cards if isinstance(x[2], board.NumberCard)
]
top_cards = [
x for x in top_cards if x[2].number == search_board.getGoal(x[2].suit) + 1
]
result = []
for source, index, card in top_cards: for source, index, card in top_cards:
if not (card.number == search_board.getGoal(card.suit) + 1):
continue
obvious = all( obvious = all(
search_board.getGoal(other_suit) >= card.number - 2 search_board.getGoal(other_suit) >= card.number - 2
for other_suit in set(board.NumberCard.Suit) - {card.suit} for other_suit in set(board.NumberCard.Suit) - {card.suit}
) )
yield board_actions.GoalAction( result.append(
card=card, board_actions.GoalAction(
source_id=index, card=card,
source_row_index=len(search_board.field[index]) - 1 source_id=index,
if source == board.Position.Field source_row_index=len(search_board.field[index]) - 1
else None, if source == board.Position.Field
source_position=source, else None,
goal_id=search_board.getGoalId(card.suit), source_position=source,
obvious=obvious, goal_id=search_board.getGoalId(card.suit),
obvious=obvious,
)
) )
break break
yield from sorted(result, key=lambda x: x.card.number)
def _can_stack(bottom: board.Card, top: board.Card) -> bool: def _can_stack(bottom: board.Card, top: board.Card) -> bool:
@@ -223,8 +227,8 @@ def possible_actions(search_board: board.Board) -> List[board_actions.Action]:
*list(possible_bunkerize_actions(search_board)), *list(possible_bunkerize_actions(search_board)),
] ]
for x in result: for action in result:
if x.automatic(): if action.automatic():
return [x] return [action]
return result return result