小编Gem*_*nus的帖子

在A*中使用可接受和一致的启发式方法

有人有一个简单和/或直观的解释,为什么你必须在A*中使用一个可接受的启发式,以及为什么你"应该"使用一致的启发式?

algorithm heuristics a-star

3
推荐指数
1
解决办法
466
查看次数

Java Nashorn中的Access对象变量

我的脚本中有一个对象,包含字段和方法.我可以用Java调用方法,invokeMethod()但似乎无法获取对象字段的内容.我有这个JavaScript代码:

var Test = { 
    TestVar: "SomeTest", 

    TestFunc: function() {
        print("Hello");
    }
};
Run Code Online (Sandbox Code Playgroud)

在这个Java类中:

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

public class ScriptTest {
    public static void main(String[] args) {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");

        try {
            engine.eval("var Test = { TestVar: \"SomeTest\", TestFunc: function() { print(\"Hello\");}};");
        } catch (ScriptException e) {
            e.printStackTrace();
            System.exit(1);
        }

        System.out.println(engine.get("Test"));
        System.out.println(engine.get("Test.TestVar"));
        System.out.println(engine.get("Test[TestVar]"));
        System.out.println(engine.get("Test[\"TestVar\"]"));

        Invocable inv = (Invocable) engine;

        try {
            inv.invokeMethod(engine.get("Test"), "TestFunc");
        } catch (NoSuchMethodException e) …
Run Code Online (Sandbox Code Playgroud)

javascript java nashorn

2
推荐指数
1
解决办法
2808
查看次数

Haskell中的Monadic TicTacToe出错

我开始在Haskell中实现TicTacToe:

import Control.Monad.State

data Player = X | O
data Field = Player | I deriving (Eq, Show, Read)

data GameField = G [[Field]]

type GameState = State GameField ()

initGame :: GameState
initGame = do
    put $ G [[I,I,I],[I,I,I],[I,I,I]]

action = do
    initGame

test = execState action $ G [[I,I,I],[I,I,I],[I,I,I]]
Run Code Online (Sandbox Code Playgroud)

当我执行"test"时,我收到以下错误:

No instance for (Show GameField) arising from a use of `print'
Possible fix: add an instance declaration for (Show GameField)
In a stmt of an interactive GHCi command: …
Run Code Online (Sandbox Code Playgroud)

monads haskell

0
推荐指数
1
解决办法
126
查看次数

标签 统计

a-star ×1

algorithm ×1

haskell ×1

heuristics ×1

java ×1

javascript ×1

monads ×1

nashorn ×1