Skip to content

Commit

Permalink
some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
h908714124 committed Aug 4, 2024
1 parent 9378dbc commit f0799bb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/main/client/src/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {
StompContext,
BLACK,
ANY_TERRITORY,
TERRITORY,
TERRITORY_B,
REMOVED_B,
ANY_REMOVED,
Expand Down Expand Up @@ -362,8 +362,8 @@ function paintStonesCounting(context, board, countingGroup) {
"rgba(255,255,255,0.25)"
showShadow(context, grid_x, grid_y, style)
}
if (color & ANY_TERRITORY) {
let style = (color & ANY_TERRITORY) === TERRITORY_B ?
if (color & TERRITORY) {
let style = (color & TERRITORY) === TERRITORY_B ?
"rgba(0,0,0)" :
"rgba(255,255,255)"
showTerritory(context, grid_x, grid_y, style)
Expand Down
4 changes: 2 additions & 2 deletions src/main/client/src/model/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export function getGroupInfo(board, xx, yy) {

export function rehydrate(board) {
let dim = board.length
let result = []
let result = Array(dim)
for (let i = 0; i < board.length; i++) {
result.push([])
result[i] = Array(dim)
}
for (let y = 0; y < board.length; y++) {
for (let x = 0; x < board[y].length; x++) {
Expand Down
11 changes: 7 additions & 4 deletions src/main/client/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import toast from "react-hot-toast"
export const StompContext = createContext()

export const base = "/app"

export const BLACK = 32
export const WHITE = 64
export const TERRITORY_B = 2
export const TERRITORY_W = 4
export const ANY_TERRITORY = TERRITORY_W | TERRITORY_B
export const REMOVED_B = 8
export const REMOVED_W = 16

export const TERRITORY = TERRITORY_W | TERRITORY_B
export const ANY_REMOVED = REMOVED_W | REMOVED_B

const COLORS = BLACK | WHITE;
const MARKERS = ~COLORS;
export const COLORS = BLACK | WHITE;

export async function tfetch(url, options) {
let response
Expand Down Expand Up @@ -60,7 +61,7 @@ function dec2hex(dec) {
}

export function hasStone(color) {
return (color & COLORS) != 0 && (color & MARKERS) == 0;
return (color & COLORS) !== 0
}

export function getBaseColor(color) {
Expand All @@ -87,6 +88,8 @@ export async function doTry(task, onError) {
} catch (e) {
if (onError) {
onError()
} else {
console.log(e)
}
toast.error(e.message)
}
Expand Down

0 comments on commit f0799bb

Please sign in to comment.