Commit graph

150 commits

Author SHA1 Message Date
Sam Atkins
364d728e66 Solitaire: Disable filling with background color during end animation
This fixes #7792.

The visual glitches with card corners, and the screen-clear when
opening a menu, were both caused by the widgets having
`fill_with_background_color` set. We need that set most of the time,
so we just disable it for the duration of the game-over animation.

Also resove a FIXME that no longer applies. :^)
2021-06-13 19:29:52 +01:00
Sam Atkins
679f831451 Solitaire: Only start timer when a move happens
Previously, the timer started if you clicked within the game area,
whether that was on a card or not. Now, we only start when you click
on a card or otherwise attempt a move.

As a bonus, we now immediately update the status bar time indicator
on game start, instead of having to wait until 1 second has elapsed.
2021-06-13 19:29:52 +01:00
Sam Atkins
8ee447b718 Solitaire: Prevent undo when the game is over 2021-06-13 19:29:52 +01:00
Sam Atkins
cf504ccc6a Solitaire: Allow automatic moves to end the game and animate
Previously, if a tab-move moved all the remaining cards to the
foundations, the game would not notice until you moved a card
away and then back again.

I had to add a 1-frame delay to starting the animation, so that it
would have time to re-paint the foundation in that case.
2021-06-13 19:29:52 +01:00
Dmitrii Ubskii
f11000b176
2048: Fix move success detection
Whether or not tiles moved used to be determined by comparing new_tiles
with m_tiles. This is no longer possible since the slide is done
in-place.

This fix makes the game look through the m_sliding_tiles, which contains
previous and current position for each tile on the board, to determine
whether any tile moved at all. If not, the move is deemed unsuccessful.

Fixes #8008.
2021-06-12 00:46:11 +01:00
Dmitrii Ubskii
242742b6c2 2048: Animate sliding tiles 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
8a8c2572b1 2048: Encapsulate away Board's inner workings
This change brings all the board twiddling code into the Board proper to
enable sliding animations further down the line.
2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
9ce5ce3560 2048: Add pop-in animation for newly added tiles 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
11158c2400 2048: Abstract Board into its own struct 2021-06-11 22:45:14 +02:00
Dmitrii Ubskii
ec8fe6952f 2048: East const all the things 2021-06-11 22:45:14 +02:00
Sam Atkins
e0fb36aad7 Solitaire: Iterate the foundation stacks and inline move_card()
Keeping this as a separate commit as I'm not certain whether this
is a good change or not. The repeated if-else for each Foundation
stack bothered me a bit, though more so before I reduced the code
in the {}. But maybe the ifs are clearer than the loop?

Doing that also meant I could inline the move_card() code instead
of needing to make it a lambda. Again, maybe it would be better as
a lambda? I'm still figuring out the style Serenity uses, and I
know Andreas is big on expressiveness, and move_card() is more
expressive than just having the code in the loop.
2021-06-11 22:42:38 +02:00
Sam Atkins
4917675529 Solitaire: Fix invisible cards when multiple are tab-moved at once
Previously, pressing <tab> to auto-move cards would render all but
the last one that moved invisible. Now they all render correctly.
:^)
2021-06-11 22:42:38 +02:00
Sam Atkins
f0dcf79116 Solitaire: Combine duplicate tab/double-click logic
The two paths did the same thing, in two different ways. Now they
are the same. :^)

Can't quite put all of the logic into
attempt_to_move_card_to_foundations() because the double-click has
to check that you clicked on the top card.
2021-06-11 22:42:38 +02:00
Sam Atkins
adedb3de2a Solitaire: Subtract points when undoing a card-flip
Solitaire: Correct default arg definition location
2021-06-11 22:42:38 +02:00
Sam Atkins
8d8b1d9531 Solitaire: Correctly score automatic moves using <tab> 2021-06-11 22:42:38 +02:00
Joshua Gollaher
eea95c4532 Chess: Remove 1:1 window aspect ratio 2021-06-11 11:31:35 +02:00
Ali Mohammad Pur
51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Gunnar Beutner
fab9b2f068 Hearts: Don't destroy the animation handler while running it 2021-06-04 19:32:25 +02:00
Timothy Flynn
2b762ef940 Solitaire+LibCards: Draw card stacks with rounded corners
Now that the cards have rounded corners, draw the stack box behind the
cards with rounded corners as well. This way, the corner of the stack
box doesn't peek out from behind the cards.

The caveat here is that the "play" card stack now needs to hold a
reference to the "waste" stack beneath it so it knows when not to draw
its background on top of the waste stack. To faciliate that, the array
of card stacks is now a NonnullRefPtrVector so the play stack can store
a smart pointer to the waste stack (instead of a raw pointer or
reference).
2021-06-04 19:11:45 +02:00
Matthew Jones
1748591570 Solitaire: Fixes undo feature from incorrect merge conflict resolution 2021-06-04 00:15:25 +02:00
Matthew B. Jones
ecaae2d10f
Solitaire: Add keys for drawing and moving cards to foundation stacks
Also shifts logic of starting game length timer into function
`start_timer_if_necessary`, so it can be called from original
mouse event handler and new `auto_move_eligible_cards_to_stacks`
2021-06-03 08:43:28 +01:00
Matthew B. Jones
ab4f4ddc3c
Solitaire: Add undo functionality 2021-06-03 01:16:49 +01:00
Matthew B. Jones
3ad7a1e944
Hearts: Play the first valid card (left-to-right) when pressing space 2021-06-02 23:07:12 +01:00
BrandonKi
ee38f5241d LibChess: Change cursor style when hovering or dragging valid piece 2021-06-02 11:18:40 +02:00
Gunnar Beutner
45117a4134 Hearts: Fix sorting for pick_low_points_high_value_card
Previously the function did not sort the hand at all which means we
wouldn't necessarily pick the card with the highest value.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
63d3beb78c Hearts: Prefer to pass high value cards
Previously we'd prefer to pass high points cards. Instead we should
prefer to pass high value cards first.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
8b9da08d5a Hearts: Pick better non-matching cards
When we don't have a matching card for the lead card rather than
always preferring to play hearts we should try to get rid of our
high value cards first if no other player has hearts cards higher
than what we have.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
4a8d8da46c Hearts: Make debugging AI suggestions easier
When building Hearts with HEARTS_DEBUG we highlight the card the AI
would have picked. This makes comparing AI and human decisions easier.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
2b2d992946 Hearts: Pick better cards when we're the third player
When we're the third player in a trick and we don't have a lower value
card we would previously pick a slightly higher value card. Instead
we should pick the highest value card unless there are points in the
current trick or the lead card is spades and the higher value card
we would've picked is higher than the queen and another player still
has the queen.

The rationale is that we have to take the trick anyway so we might as
well get rid of our highest value card. If the trailing player has a
lower value card of the same type we take the trick but don't gain
any points. If they don't have a card of the same type it doesn't
matter whether we play a high value or low value card.
2021-06-01 08:52:08 +02:00
Gunnar Beutner
38f8a6aabb Hearts: Pick better lead cards
Previously the AI would prefer playing a lead card for which no other
player had a card with a higher value even though it also had a card
for which a higher value card was still in play.
2021-06-01 08:52:08 +02:00
Marcus Nilsson
f7667901ed Solitaire: Start timer when first card is moved
Starts the game timer when the first card is clicked or moved instead of
when a new game is started.

Fixes #7489
2021-05-27 22:55:37 +02:00
Gunnar Beutner
971f4ca71c Hearts: Highlight cards when an invalid play is attempted
This briefly inverts the selected card when the user attempts to make
an invalid play.
2021-05-26 19:57:08 +02:00
Timothy Flynn
a428812ba2 Solitaire: Persist high score separately per game mode
With different scoring rules for one-card vs. three-card draw mode, it
makes more sense to separately track their high scores.
2021-05-25 21:20:50 +02:00
Timothy Flynn
5d4cca7e0c Solitaire: Award bonus points based on time elapsed
The exact formula used for bonus points seems to vary by implementation.
This uses Klondike Solitaire's formula:

    https://en.wikipedia.org/wiki/Klondike_(solitaire)#Scoring
2021-05-25 21:20:50 +02:00
Timothy Flynn
0f80e9e4db Solitaire: Tweak scoring for three-card draw mode
Currently, the player loses 100 points each time the waste stack is
recycled. In three-card draw mode, it's standard to only lose 20 points
after the third recycle event.
2021-05-25 21:20:50 +02:00
Timothy Flynn
cf9094cf46 Solitaire: Remove dead call to Game::start_game_over_animation
This invocation will exit immediately. There's also no reason to invoke
stop_game_over_animation here because that's the first thing that will
happen in the call to setup.
2021-05-25 21:20:50 +02:00
Timothy Flynn
0b30a0febb Solitaire: Only update high score after a victorious game
Doesn't make much sense to update the high score on a lost game.
2021-05-25 21:20:50 +02:00
Gunnar Beutner
95401d2ca2 Hearts: Don't advance the game's state when an animation is playing
Previously we'd end up cancelling an animation that was still playing
when the user selects a card.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
fc99aa92bd Hearts: Fix animations that get stuck "mid-flight"
When an animation is stopped the cards should be moved to their final
position anyway. Otherwise they might end up getting stuck in the
middle of the animation.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
87ace131bc Hearts: Add support for playing more than one hand
This changes the game so that more than one hand can be played. Once
one player has 100 or more points the game ends. A score card is shown
between each hand.

Fixes #7374.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
e636ed43eb Hearts: Let the AI continuously play games
When there are no human players (toggled with Shift-F10) the AI will
continuously start new games when the current game has finished.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
ac1eba2f7c Hearts: Implement passing cards to other players
Fixes #7375.
2021-05-25 21:05:35 +02:00
Gunnar Beutner
fab073f33c Hearts: Move card click handler into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
89d38b7e94 Hearts: Move sorting helper from Player::pick_lead_card into a method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
4ba9cc82c0 Hearts: Move code to reposition cards into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
9a6c6a98e5 Hearts: Move round initialization into a separate method 2021-05-25 21:05:35 +02:00
Gunnar Beutner
4e3a1f2da9 Hearts: Move hand sorting functionality into a method 2021-05-25 21:05:35 +02:00
Josh Perry
d27616cf36 Hearts: Allow player to set their name
Added a new settings dialog to Hearts with a textbox to allow the
player to set a name, which is persisted in the Hearts config file.
2021-05-23 20:43:53 +01:00
Gunnar Beutner
6a194869cf Hearts: Add key combinations to letting the AI play for you
A single card can be played with F10 while Shift-F10 toggles the AI
for the current as well as all future tricks.
2021-05-23 18:15:36 +02:00
Gunnar Beutner
2dfced2501 Hearts: Let the AI prefer lead cards for which other cards are in play
When picking a lead card the AI should avoid playing cards where it
knows that no other player has a lower value card of the same type.
2021-05-23 18:15:36 +02:00