Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ common --java_runtime_version=remotejdk_25
common --tool_java_language_version=25
common --tool_java_runtime_version=remotejdk_25

build --experimental_strict_java_deps=error
build --experimental_java_classpath=bazel

# build --strategy=Scalac=worker

# layering check fails because golf_service:handlers depends on :protobuf for json_util.h
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- name: bazel-format-check
run: |
bazel run //:format.check
# Dependencies are pre-installed in the Docker image
# No need to run setup-linux anymore!
- name: Create bazel-diff output directory
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ jobs:
build --remote_cache=https://storage.googleapis.com/moon_base_build_cache
build --remote_upload_local_results=true

- name: bazel-format-check
run: |
bazel run //:format.check

- name: bazel-test
run: |
bazel build //... && bazel test //...
Expand All @@ -46,4 +50,3 @@ jobs:
- name: bazel-run-oci-push
run: |
bazel query 'kind(oci_push, //...)' | xargs -n1 bazel run

10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@buildifier_prebuilt//:rules.bzl", "buildifier", "buildifier_test")

alias(
name = "format",
actual = "//bazel/format",
)

alias(
name = "format.check",
actual = "//bazel/format:format.check",
)

gazelle(name = "gazelle")

buildifier(
Expand Down
393 changes: 389 additions & 4 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions bazel/format/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@aspect_rules_lint//format:defs.bzl", "format_multirun")
load("@rules_java//java:defs.bzl", "java_binary")

java_binary(
name = "java-format",
jvm_flags = [
"--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",
"--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED",
],
main_class = "com.google.googlejavaformat.java.Main",
runtime_deps = ["@google-java-format//jar"],
)

format_multirun(
name = "format",
java = ":java-format",
visibility = ["//visibility:public"],
)
9 changes: 9 additions & 0 deletions bazel/tools.MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,12 @@ bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2", dev_dependency = Tr

bazel_dep(name = "bazel-diff", version = "12.1.1")
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "aspect_rules_lint", version = "2.0.0")

http_jar = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")

http_jar(
name = "google-java-format",
sha256 = "697707af07c7753f29cba415c6a76b7882702ff464f807da98b28069b8751910",
url = "https://repo1.maven.org/maven2/com/google/googlejavaformat/google-java-format/1.33.0/google-java-format-1.33.0-all-deps.jar",
)
31 changes: 22 additions & 9 deletions jvm/src/main/java/com/muchq/cards/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@
import java.util.List;

public record Card(Suit suit, Rank rank) {
private static final List<Suit> SUITS = List.of(Suit.CLUBS, Suit.DIAMONDS, Suit.HEARTS, Suit.SPADES);
private static final List<Rank> RANKS = List.of(
Rank.TWO, Rank.THREE, Rank.FOUR, Rank.FIVE, Rank.SIX, Rank.SEVEN, Rank.EIGHT,
Rank.NINE, Rank.TEN, Rank.JACK, Rank.QUEEN, Rank.KING, Rank.ACE);
private static final List<Suit> SUITS =
List.of(Suit.CLUBS, Suit.DIAMONDS, Suit.HEARTS, Suit.SPADES);
private static final List<Rank> RANKS =
List.of(
Rank.TWO,
Rank.THREE,
Rank.FOUR,
Rank.FIVE,
Rank.SIX,
Rank.SEVEN,
Rank.EIGHT,
Rank.NINE,
Rank.TEN,
Rank.JACK,
Rank.QUEEN,
Rank.KING,
Rank.ACE);

public static Card forIndex(int index) {
Suit s = SUITS.get(index % 4);
Rank r = RANKS.get(index % 13);
return new Card(s, r);
}
public static Card forIndex(int index) {
Suit s = SUITS.get(index % 4);
Rank r = RANKS.get(index % 13);
return new Card(s, r);
}
}
60 changes: 30 additions & 30 deletions jvm/src/main/java/com/muchq/cards/Deck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,41 @@
import java.util.List;

public record Deck(Deque<Card> cards) {

public boolean hasNext() {
return !cards.isEmpty();
}

public Card nextCard() {
return cards.removeLast();
}
public boolean hasNext() {
return !cards.isEmpty();
}

public Deck shuffled() {
List<Card> newCards = new ArrayList<>(cards);
Collections.shuffle(newCards);
return new Deck(new ArrayDeque<>(newCards));
}
public Card nextCard() {
return cards.removeLast();
}

public static Deck withJokers() {
var cards = cardsListWithNoJokers();
cards.add(new Card(Suit.NONE, Rank.JOKER));
cards.add(new Card(Suit.NONE, Rank.JOKER));
return new Deck(cards);
}
public Deck shuffled() {
List<Card> newCards = new ArrayList<>(cards);
Collections.shuffle(newCards);
return new Deck(new ArrayDeque<>(newCards));
}

public static Deck noJokers() {
return new Deck(cardsListWithNoJokers());
}
public static Deck withJokers() {
var cards = cardsListWithNoJokers();
cards.add(new Card(Suit.NONE, Rank.JOKER));
cards.add(new Card(Suit.NONE, Rank.JOKER));
return new Deck(cards);
}

public static Deck noJokers() {
return new Deck(cardsListWithNoJokers());
}

private static Deque<Card> cardsListWithNoJokers() {
List<Card> cards = new ArrayList<>();
for (var suit : Suit.values()) {
for (var value : Rank.values()) {
if (suit != Suit.NONE && value != Rank.JOKER) {
cards.add(new Card(suit, value));
}
}
private static Deque<Card> cardsListWithNoJokers() {
List<Card> cards = new ArrayList<>();
for (var suit : Suit.values()) {
for (var value : Rank.values()) {
if (suit != Suit.NONE && value != Rank.JOKER) {
cards.add(new Card(suit, value));
}
return new ArrayDeque<>(cards);
}
}
return new ArrayDeque<>(cards);
}
}
28 changes: 14 additions & 14 deletions jvm/src/main/java/com/muchq/cards/Rank.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.muchq.cards;

public enum Rank {
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE,
JOKER
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE,
JOKER
}
10 changes: 5 additions & 5 deletions jvm/src/main/java/com/muchq/cards/Suit.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.muchq.cards;

public enum Suit {
CLUBS,
DIAMONDS,
HEARTS,
SPADES,
NONE;
CLUBS,
DIAMONDS,
HEARTS,
SPADES,
NONE;
}
4 changes: 1 addition & 3 deletions jvm/src/main/java/com/muchq/cards/castle/GameState.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.muchq.cards.castle;

import com.muchq.cards.Card;

import java.util.Deque;
import java.util.List;

public record GameState(Deque<Card> drawPile, List<Player> players, Turn lastPlayed) {
}
public record GameState(Deque<Card> drawPile, List<Player> players, Turn lastPlayed) {}
4 changes: 1 addition & 3 deletions jvm/src/main/java/com/muchq/cards/castle/Player.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.muchq.cards.castle;

import com.muchq.cards.Card;

import java.util.List;

public record Player(String name, List<Card> hand, ThreeUp faceUp, ThreeDown faceDown) {
}
public record Player(String name, List<Card> hand, ThreeUp faceUp, ThreeDown faceDown) {}
7 changes: 3 additions & 4 deletions jvm/src/main/java/com/muchq/cards/castle/ThreeDown.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.muchq.cards.castle;

import com.muchq.cards.Card;

import java.util.Optional;

public record ThreeDown(Optional<Card> left, Optional<Card> center, Optional<Card> right) {
public boolean isEmpty() {
return left().isEmpty() && center().isEmpty() && right().isEmpty();
}
public boolean isEmpty() {
return left().isEmpty() && center().isEmpty() && right().isEmpty();
}
}
7 changes: 3 additions & 4 deletions jvm/src/main/java/com/muchq/cards/castle/ThreeUp.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.muchq.cards.castle;

import com.muchq.cards.Card;

import java.util.Optional;

public record ThreeUp(Optional<Card> left, Optional<Card> center, Optional<Card> right) {
public boolean isEmpty() {
return left().isEmpty() && center().isEmpty() && right().isEmpty();
}
public boolean isEmpty() {
return left().isEmpty() && center().isEmpty() && right().isEmpty();
}
}
3 changes: 1 addition & 2 deletions jvm/src/main/java/com/muchq/cards/castle/Turn.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

import com.muchq.cards.Rank;

public record Turn(Rank rank, int howMany) {
}
public record Turn(Rank rank, int howMany) {}
14 changes: 7 additions & 7 deletions jvm/src/main/java/com/muchq/chess_com_api/Best.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.Instant;

public record Best(int rating, Instant instant, String gameUrl) {
@JsonCreator
public static Best create(@JsonProperty("rating") int rating,
@JsonProperty("date") int epochSeconds,
@JsonProperty("game") String gameUrl) {
return new Best(rating, Instant.ofEpochSecond(epochSeconds), gameUrl);
}
@JsonCreator
public static Best create(
@JsonProperty("rating") int rating,
@JsonProperty("date") int epochSeconds,
@JsonProperty("game") String gameUrl) {
return new Best(rating, Instant.ofEpochSecond(epochSeconds), gameUrl);
}
}
Loading
Loading