import { BoardSelectors } from "@shoki/board" ; import { createUtilityValue , ScoringDirection } from "@shoki/engine" ; import { PlayerState , PlayerStateSelectors , PlayerActions , getAllPieces } from "@creature-chess/gamemode" ; import { PieceModel } from "@creature-chess/models" ; import { BotPersonality } from "@creature-chess/data" ; import { BrainAction } from "../../brain" ; import { isStrategicPiece } from "./utils/creatureType" ; export const createSellPieceAction = ( state , personality , piece ) : BrainAction | null => { const pieceCount = PlayerStateSelectors . getAllPieceCount ( state ) ; const allPieces = getAllPieces ( state ) ; const boardPieces = BoardSelectors . getAllPieces ( state . board ) ; const hasMatchingPieceOnBoard = boardPieces . some ( p => p . definitionId === piece . definitionId ) ; if ( ( pieceCount - 1 ) < PlayerStateSelectors . getPlayerLevel ( state ) ) { return null ; } if ( isStrategicPiece ( piece , allPieces ) ) { return null ; } if ( hasMatchingPieceOnBoard ) { return null ; } const money = PlayerStateSelectors . getPlayerMoney ( state ) ; return ( { name : `sell piece [${ piece . definition . name }]` , action : ( ) => PlayerActions . sellPiecePlayerAction ( { pieceId : piece . id } ) , value : createUtilityValue ( [ { value : money , range : [ 1 , 20 ] , direction : ScoringDirection . Low , weighting : { value : personality . composure , direction : ScoringDirection . Low } } , { value : piece . definition . cost , range : [ 1 , 5 ] , direction : ScoringDirection . Low , weighting : { value : personality . ambition , direction : ScoringDirection . High } } ] ) } ) ; } ;