Skip to content

Commit

Permalink
good enough for the night.
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerelSchwerz committed Mar 9, 2024
1 parent 86dbd57 commit d03d9c6
Show file tree
Hide file tree
Showing 14 changed files with 680 additions and 710 deletions.
828 changes: 414 additions & 414 deletions src/ThePathfinder.ts

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions src/mineflayer-specific/movements/interactionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class InteractHandler {

protected _internalLock = true

protected task?: Task<void, Error>;
protected task?: Task<void, Error>

public readonly blockInfo: BlockInfo
// public readonly bb: AABB
Expand All @@ -65,7 +65,6 @@ export abstract class InteractHandler {
public get bb (): AABB {
return AABB.fromBlock(this.vec)
}


constructor (
public readonly x: number,
Expand Down Expand Up @@ -124,7 +123,7 @@ export abstract class InteractHandler {
this._done = true
this.performing = false

if (this.task && this.task.canceled) return
if (this.task?.canceled != null) return
// this.task.cancel(err);
throw new CancelError(`Failed to perform ${this.constructor.name}`, err)
})
Expand Down Expand Up @@ -529,7 +528,7 @@ export class PlaceHandler extends InteractHandler {
}

async abort (bot: Bot): Promise<void> {
if (this.task && !this.task.done) {
if ((this.task != null) && !this.task.done) {
this.task.finish()
this.task.canceled = true
}
Expand Down Expand Up @@ -630,7 +629,7 @@ export class BreakHandler extends InteractHandler {
this._breakTask = bot.dig(block, 'ignore', 'raycast')

await this._breakTask
this.task!.finish()
if (this.task != null) this.task.finish()
break
}

Expand All @@ -656,7 +655,7 @@ export class BreakHandler extends InteractHandler {
}

async abort (bot: Bot): Promise<void> {
if (this.task && !this.task.done) {
if ((this.task != null) && !this.task.done) {
this.task.finish()
this.task.canceled = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/mineflayer-specific/movements/movement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export abstract class Movement {
public readonly world: World
public settings: MovementOptions

/**
/**
* Current move being executed.
*
* This move is the same as the thisMove argument provided to functions.
Expand Down
1 change: 0 additions & 1 deletion src/mineflayer-specific/movements/movementExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export interface CompleteOpts {
}

export abstract class MovementExecutor extends Movement {

/**
* Physics engine, baby.
*/
Expand Down
25 changes: 12 additions & 13 deletions src/mineflayer-specific/movements/movementProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export abstract class MovementProvider extends Movement {

// let i = 0
// while (move !== undefined && i++ < 3) { // 5 levels

// for (const m of move.toPlace) {
// if (m.x === yes.x && m.y === yes.y && m.z === yes.z) {
// return m.blockInfo
Expand Down Expand Up @@ -106,10 +106,9 @@ export abstract class MovementProvider extends Movement {
wantedDz >= this.boundaries[1] ||
wantedDy < 0 ||
wantedDy >= this.boundaries[2]
)
return this.world.getBlockInfo(yes)
// return super.getBlockInfo(pos, dx, dy, dz)
// console.log('out of bounds', pos, this.orgPos, wantedDx, wantedDy, wantedDz, this.boundaries)
) { return this.world.getBlockInfo(yes) }
// return super.getBlockInfo(pos, dx, dy, dz)
// console.log('out of bounds', pos, this.orgPos, wantedDx, wantedDy, wantedDz, this.boundaries)
// }

const idx = wantedDx * this.boundaries[2] * this.boundaries[1] + wantedDz * this.boundaries[2] + wantedDy
Expand Down Expand Up @@ -142,7 +141,7 @@ export abstract class MovementProvider extends Movement {
// throw new Error('dang')
// }

return data as BlockInfo
return data
}

const ret = this.world.getBlockInfo(yes)
Expand Down Expand Up @@ -188,7 +187,7 @@ export class MovementHandler implements AMovementProvider<Move> {
this.goal = goal
}

private readonly boundaries: [x: number, z: number, y: number] = [7,7,7]
private readonly boundaries: [x: number, z: number, y: number] = [7, 7, 7]
private readonly halfway: [x: number, z: number, y: number] = [Math.floor(this.boundaries[0] / 2), Math.floor(this.boundaries[1] / 2), Math.floor(this.boundaries[2] / 2)]

private readonly maxBound = this.boundaries[0] * this.boundaries[1] * this.boundaries[2]
Expand Down Expand Up @@ -244,12 +243,12 @@ export class MovementHandler implements AMovementProvider<Move> {
MovementHandler.totCount++
}

preloadInteractData(move: Move): void {
preloadInteractData (move: Move): void {
// data has already been shifted, no need to worry.
let move1: Move | undefined = move
let exit = false;
let exit = false

const seen = new Set<number>();
const seen = new Set<number>()

// theoretically, this is incorrect. Newest iteration should occur, not oldest.
// reverse by starting at root then traversing down.
Expand All @@ -262,7 +261,7 @@ export class MovementHandler implements AMovementProvider<Move> {
else if (!seen.has(idx)) {
this.localData[idx] = m.blockInfo
seen.add(idx)
} else break;
} else break
}

for (const m of move1.toBreak) {
Expand All @@ -271,9 +270,9 @@ export class MovementHandler implements AMovementProvider<Move> {
else if (!seen.has(idx)) {
this.localData[idx] = m.blockInfo
seen.add(idx)
} else break;
} else break
}
move1 = move1.parent
move1 = move1.parent
}
// if (i > 1) console.log('i', i)
}
Expand Down
6 changes: 6 additions & 0 deletions src/mineflayer-specific/movements/movementProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ export class ForwardDropDown extends DropDownProvider {

if (block0.liquid) cost += this.settings.liquidCost

// drop cost
cost += (node.y - blockLand.position.y) * 0.5

const blockA = this.getBlockInfo(node, dir.x, 2, dir.z)
const blockB = this.getBlockInfo(node, dir.x, 1, dir.z)
const blockC = this.getBlockInfo(node, dir.x, 0, dir.z)
Expand Down Expand Up @@ -331,6 +334,9 @@ export class StraightDown extends DropDownProvider {

if (block0.liquid) cost += this.settings.liquidCost // dont go underwater

// drop cost
cost += (node.y - blockLand.position.y) * 0.5

const block1 = this.getBlockInfo(node, 0, -1, 0)

const toBreak: BreakHandler[] = []
Expand Down
48 changes: 22 additions & 26 deletions src/mineflayer-specific/pathProducers/continuousPathProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ContinuousPathProducer implements PathProducer {

private readonly gcInterval: number = 10
private lastGc: number = 0
private lastStartTime = performance.now()
private readonly lastStartTime = performance.now()
constructor (start: Move, goal: goals.Goal, settings: MovementOptions, bot: Bot, world: World, movements: ExecutorMap) {
this.start = start
this.goal = goal
Expand Down Expand Up @@ -66,31 +66,27 @@ export class ContinuousPathProducer implements PathProducer {

// debug all same info in partialPathProducer

const cost = this.astarContext?.bestNode?.g ?? 0
const nodecount = this.astarContext?.nodeConsiderCount ?? 0
const seensize = this.astarContext?.closedDataSet.size ?? 0
const movecount = this.astarContext?.moveConsiderCount ?? 0



const time1 = performance.now() - this.lastStartTime


console.log('\nthis iter:', time1)
console.log('itered considered nodes', nodecount, 'nodes/s', (nodecount / time1) * 1000)
console.log('itered seen size', seensize, 'nodes/s', (seensize / time1) * 1000)
console.log('itered move considered', movecount, 'nodes/s', (movecount / time1) * 1000)

console.log("locality %", (MovementHandler.count / MovementHandler.totCount) * 100);
console.log("cost", cost)
console.log("path length", result.path.length)
// this.lastStartTime = performance.now()
// const time = performance.now() - this.startTime
// console.log('\ntotal', time, 'ms')
// console.log('total considered nodes', this.consideredNodeCount, time, (this.consideredNodeCount / time) * 1000, 'nodes/s')
// console.log('total seen size', this.latestClosedNodeCount, time, (this.latestClosedNodeCount / time) * 1000, 'nodes/s')
// console.log('total move considered', this.latestMoveCount, time, (this.latestMoveCount / time) * 1000, 'nodes/s')

const cost = this.astarContext?.bestNode?.g ?? 0
const nodecount = this.astarContext?.nodeConsiderCount ?? 0
const seensize = this.astarContext?.closedDataSet.size ?? 0
const movecount = this.astarContext?.moveConsiderCount ?? 0

const time1 = performance.now() - this.lastStartTime

console.log('\nthis iter:', time1)
console.log('itered considered nodes', nodecount, 'nodes/s', (nodecount / time1) * 1000)
console.log('itered seen size', seensize, 'nodes/s', (seensize / time1) * 1000)
console.log('itered move considered', movecount, 'nodes/s', (movecount / time1) * 1000)

console.log('locality %', (MovementHandler.count / MovementHandler.totCount) * 100)
console.log('cost', cost)
console.log('path length', result.path.length)
// this.lastStartTime = performance.now()
// const time = performance.now() - this.startTime
// console.log('\ntotal', time, 'ms')
// console.log('total considered nodes', this.consideredNodeCount, time, (this.consideredNodeCount / time) * 1000, 'nodes/s')
// console.log('total seen size', this.latestClosedNodeCount, time, (this.latestClosedNodeCount / time) * 1000, 'nodes/s')
// console.log('total move considered', this.latestMoveCount, time, (this.latestMoveCount / time) * 1000, 'nodes/s')

return { result, astarContext: this.astarContext }
}
Expand Down
Loading

0 comments on commit d03d9c6

Please sign in to comment.