Skip to content

Commit

Permalink
Parse maritime trade freqdeck in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
zarns committed Nov 3, 2024
1 parent 7c6ad6e commit a7ec879
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions ui/src/components/Prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,29 @@ export function humanizeAction(gameState, action) {
}

export function humanizeTradeAction(action) {
const out = action[2].slice(0, 4).filter((resource) => resource !== null);
return `${out.length} ${out[0]} => ${action[2][4]}`;
const freqdeck = action[2];
const RESOURCES = ['WOOD', 'BRICK', 'SHEEP', 'WHEAT', 'ORE'];

const resourcesGiven = [];
const resourcesReceived = [];

// Parse resources given (indices 0-4)
for (let i = 0; i < 5; i++) {
const amount = freqdeck[i];
if (amount > 0) {
resourcesGiven.push(`${amount} ${RESOURCES[i]}`);
}
}

// Parse resources received (indices 5-9)
for (let i = 5; i < 10; i++) {
const amount = freqdeck[i];
if (amount > 0) {
resourcesReceived.push(`${amount} ${RESOURCES[i - 5]}`);
}
}

return `${resourcesGiven.join(', ')} => ${resourcesReceived.join(', ')}`;
}

function humanizePrompt(current_prompt) {
Expand Down

0 comments on commit a7ec879

Please sign in to comment.