This commit is contained in:
Robert Bendun 2021-03-29 03:40:37 +02:00
parent 7c7a055a4a
commit eeb5ef4948
3 changed files with 30 additions and 57 deletions

View File

@ -13,14 +13,15 @@
<!-- Modules --> <!-- Modules -->
<script src="modules/configuration.js"></script>
<script src="modules/utilities.js"></script>
<script src="modules/floor.js"></script> <script src="modules/floor.js"></script>
<script src="modules/grid.js"></script> <script src="modules/grid.js"></script>
<script src="modules/agentController.js"></script> <script src="modules/agentController.js"></script>
<script src="modules/agent.js"></script> <script src="modules/agent.js"></script>
<script src="modules/products.js"></script> <script src="modules/products.js"></script>
<script src="modules/knowledge.js"></script> <script src="modules/knowledge.js"></script>
<script src="modules/configuration.js"></script>
<script src="modules/utilities.js"></script>
<script src="modules/shop.js"></script> <script src="modules/shop.js"></script>
<!-- Main script file --> <!-- Main script file -->

View File

@ -1,7 +1,6 @@
function flattenToUnique(array, view = x => x) { function flattenToUnique(array, view) {
return array.reduce((set, value) => { return array.reduce((set, value) => {
const v = view(value) const v = view(value)
console.log(v)
v && v.forEach(cat => set.add(cat)) v && v.forEach(cat => set.add(cat))
return set return set
}, new Set()) }, new Set())
@ -61,6 +60,26 @@ class SemanticNetwork {
class AgentSemanticNetwork extends SemanticNetwork {} class AgentSemanticNetwork extends SemanticNetwork {}
function nearbyStorageUnitsCoords(gridX, gridY) {
function outsideOfStorageCenter(v) {
const { x, y, w, h } = StorageCenterLocation
return v.x <= x || v.x >= x + w || v.y <= y || v.y >= y + h
}
return (gridX % UnitsInGroupCount == 0
? (gridY % 3 == 1
? /* skrzyżowanie */[[-1, -1], [-1, 1], [1, -1], [1, 1]]
: /* korytarz góra-dół */[[-1, 0], [1, 0]])
: /* korytarz lewo-prawo */[[0, -1], [0, 1]])
.map(([xoff, yoff]) => ({ x: gridX + xoff, y: yGrid + yoff }))
.filter(outsideOfStorageCenter)
}
function nearbyStorageUnitsIndexes(gridX, gridY) {
return nearbyStorageUnitsCoords(gridX, gridY)
.map(({ x, y }) => x * UnitsCount + y * UnitsCount * RowsOfGroupsCount)
}
class Arrangement { class Arrangement {
constructor() { constructor() {
this.products = [...Array(UnitsCount)].map(() => ({ this.products = [...Array(UnitsCount)].map(() => ({
@ -69,6 +88,11 @@ class Arrangement {
icon: '' icon: ''
})) }))
} }
nearbyProducts(gridX, gridY) {
return nearbyStorageUnitsIndexes(gridX, gridY)
.map(i => this.products[i])
}
} }
class Knowledge { class Knowledge {

View File

@ -1,56 +1,6 @@
/**
* Zwraca koordynaty półek przy danym kafelku ścieżki
* @param {number} gridX
* @param {number} gridY
* @returns {{x:number;y:number}[]} Koordynaty sąsiednich półek do kafelka
*/
function nearbyStorageUnitsCoords(gridX, gridY) {
function outsideOfStorageCenter(v) {
const { x, y, w, h } = StorageCenterLocation
return v.x <= x || v.x >= x + w || v.y <= y || v.y >= y + h
}
return (gridX % UnitsInGroupCount == 0
? (gridY % 3 == 1
? /* skrzyżowanie */[[-1, -1], [-1, 1], [1, -1], [1, 1]]
: /* korytarz góra-dół */[[-1, 0], [1, 0]])
: /* korytarz lewo-prawo */[[0, -1], [0, 1]])
.map(([xoff, yoff]) => ({ x: gridX + xoff, y: yGrid + yoff }))
.filter(outsideOfStorageCenter)
}
/**
* Zwraca indeksy półek przy danym kafelku ścieżki
* @param {number} gridX
* @param {number} gridY
* @returns {{x:number;y:number}[]} Indeksy sąsiednich półek do kafelka
*/
function nearbyStorageUnitsIndexes(gridX, gridY) {
return nearbyStorageUnitsCoords(gridX, gridY)
.map(({ x, y }) => x * UnitsCount + y * UnitsCount * RowsOfGroupsCount)
}
function ensureArray(maybeArray) {
return Array.isArray(maybeArray) ? maybeArray : []
}
class Shop { class Shop {
constructor(semanticNetwork) {
this.semanticNetwork = semanticNetwork
this.products = [...Array(UnitsCount)].map(x => ({ name: '', count: 0 }))
}
/**
* Zwraca listę produktów w okolicy danego kafelka ścieżki
* @param {number} gridX
* @param {number} gridY
*/
nearbyProducts(gridX, gridY) {
return nearbyStorageUnitsIndexes(gridX, gridY)
.map(i => this.productPlacement[i])
}
productsSimilarityScore(name1, name2) { productsSimilarityScore(name1, name2) {
const [ o1, o2 ] = [name1, name2].map(name => this.semanticNetwork.findByName(name)) const [ o1, o2 ] = [name1, name2].map(name => Knowledge.semanticNetwork.findByName(name))
if (!o1 || !o2) if (!o1 || !o2)
throw new Error("names should be in semantic network!") throw new Error("names should be in semantic network!")
@ -67,5 +17,3 @@ class Shop {
return l <= Number.EPSILON ? c * 0.7 : l * 0.65 + c * 0.35 // TODO: maybe find better formula? needs testing return l <= Number.EPSILON ? c * 0.7 : l * 0.65 + c * 0.35 // TODO: maybe find better formula? needs testing
} }
} }
const shop = new Shop(semanticNetwork)