mirror of
https://github.com/lscharen/iigs-sprite-compiler.git
synced 2024-12-21 01:29:59 +00:00
Change the success function to allow the order of the succesors to be controlled
This commit is contained in:
parent
b7a3af9437
commit
5fc5a254ab
@ -6,7 +6,7 @@
|
||||
public interface ISearchProblem<A, S, C>
|
||||
where C : IComparable<C>
|
||||
{
|
||||
IDictionary<A, S> Successors(S state);
|
||||
IEnumerable<Tuple<A, S>> Successors(S state);
|
||||
bool IsGoal(S state);
|
||||
C StepCost(S fromState, A action, S toState);
|
||||
C Heuristic(S state);
|
||||
|
@ -1,9 +1,10 @@
|
||||
namespace SpriteCompiler.AI
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public interface ISuccessorFunction<A, S>
|
||||
{
|
||||
IDictionary<A, S> Successors(S state);
|
||||
IEnumerable<Tuple<A, S>> Successors(S state);
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ namespace SpriteCompiler.AI
|
||||
{
|
||||
foreach (var successor in problem.Successors(node.State))
|
||||
{
|
||||
var action = successor.Key;
|
||||
var state = successor.Value;
|
||||
var action = successor.Item1;
|
||||
var state = successor.Item2;
|
||||
var next = CreateNode(node, state);
|
||||
|
||||
next.Action = action;
|
||||
|
@ -22,7 +22,7 @@ namespace SpriteCompiler.AI
|
||||
this.heuristicFn = heuristicFn;
|
||||
}
|
||||
|
||||
public IDictionary<A, S> Successors(S state)
|
||||
public IEnumerable<Tuple<A, S>> Successors(S state)
|
||||
{
|
||||
return successorFn.Successors(state);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
public sealed class SpriteGeneratorSuccessorFunction : ISuccessorFunction<CodeSequence, SpriteGeneratorState>
|
||||
{
|
||||
public IDictionary<CodeSequence, SpriteGeneratorState> Successors(SpriteGeneratorState state)
|
||||
public IEnumerable<Tuple<CodeSequence, SpriteGeneratorState>> Successors(SpriteGeneratorState state)
|
||||
{
|
||||
// This is the work-horse of the compiler. For a given state we need to enumerate all of the
|
||||
// potential next operations.
|
||||
@ -26,7 +26,8 @@
|
||||
// 3. Single-byte at the end of a solid run
|
||||
// a. If no registers are 8-bit, LDA #Imm/STA 0,s (8 cycles, sets Acc)
|
||||
// b. If any reg is already 8-bit, LDA #imm/PHA (6 cycles)
|
||||
|
||||
//
|
||||
// We al
|
||||
var actions = new List<CodeSequence>();
|
||||
var bytes = state.Bytes.ToDictionary(x => x.Offset, x => x);
|
||||
|
||||
@ -117,7 +118,7 @@
|
||||
}
|
||||
|
||||
// Run through the actions to create a dictionary
|
||||
return actions.ToDictionary(x => x, x => x.Apply(state));
|
||||
return actions.Select(x => Tuple.Create(x, x.Apply(state)));
|
||||
}
|
||||
|
||||
private Func<SpriteByte, bool> WithinRangeOf(int addr, int range)
|
||||
|
Loading…
Reference in New Issue
Block a user