问题列表 - 第11485页

游戏求解算法(Buttonia,Lights-out变体)

我正在尝试为游戏算法创建一个可解决性函数.基本上是一个函数,如果可以解决,它会为给定的游戏返回true或false.

该游戏是Buttonia.com(尚未实现该算法),这是一种熄灯游戏.基本上你有一个按钮网格,按下时,每个按钮都会改变它的某些邻居的状态.目前我生成随机游戏配置,然后尽可能应用启发式.其余的是由强力搜索决定的.

到目前为止,我的进步是建立一个方程系统来模拟游戏.由于每个按钮需要改变状态奇数次才能以向下状态结束,因此它的等式是这样的:

button_A = 1 - (button_1 + button_2 + ... + button_X)%2

其中button_1到button_X是按钮状态,对button_A有效.如果某些按钮不依赖于其他按钮,则可以立即解决这些按钮.其余的,我尝试一个配置,直到我遇到冲突,然后回溯.

目前,该算法适用于较小的游戏配置.我已经从3x3游戏测试了它,尺寸为10x10.其中6x6接近实际游戏的上限.

这些方程式大大减少了蛮力的搜索空间,使其变得实用.可能存在解决方程组的纯粹数学方法.


ascii中的3x3游戏示例(来自buttonia.com/?game=2964):

||#
-o-
+#|

Legend:
o = affect only self
- = affect left and right neighbors
| = affect above and below neighbors
+ = affect left, right, above and below neighbors
# = affect all 8 surrounding neighbors
Run Code Online (Sandbox Code Playgroud)

解决方案,按下这些:(0,0),(2,0),(1,2),(0,1),(1,1),(2,1)

这个游戏的等式:

Button_0_0 = 1 - (0) % 2
Button_1_0 = 1 - (Button_2_0) % 2
Button_2_0 = 1 - (0) …
Run Code Online (Sandbox Code Playgroud)

algorithm math xor solver

6
推荐指数
1
解决办法
2913
查看次数

如何在vim中覆盖默认语法高亮?

在VIM中,我需要执行一个简单的任务 - 突出显示"("和")".我可以通过发出两个命令轻松地做到这一点:

:syn match really_unique_name display "[()]"
:hi really_unique_name guifg=#FF0000
Run Code Online (Sandbox Code Playgroud)

但是如果我添加相同的命令(当然没有':')来清空.vimrc并重新启动VIM - "("和")"在.cpp文件中不再突出显示.看来,如果我创建/加载.cpp文件,VIM会加载语法文件,覆盖我的自定义高亮显示.如何在我的.vimrc文件中配置高亮显示,以便它在标准语法定义之后发生,或者不受标准语法定义的影响?

vim vim-syntax-highlighting

12
推荐指数
3
解决办法
8059
查看次数

从UserControl外部绑定到命令

我有一个简单的UserControl包含Label,ComboBox和Button.简而言之,它几乎可以在我的几乎所有视图中使用,每次使用不同的ItemsSource和CreateItemCommand使用Bindings到我的ViewModel属性.

Label和ComboBox是另一个UserControl(LabeledComboBox)的一部分,它工作正常.

问题是,当我尝试在包含我的UserControl的窗口中绑定命令时,我得到以下异常:

无法在'MutableComboBox'类型的'CreateItemCommand'属性上设置'绑定'.'绑定'只能在DependencyObject的DependencyProperty上设置.

这是MutableComboBox的XAML:

<UserControl x:Class="Albo.Presentation.Templates.MutableComboBox"
x:Name="MCB"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:uc="clr-namespace:Albo.Presentation.Templates" >
<StackPanel Height="25" Orientation="Horizontal">
    <uc:LabeledComboBox x:Name="ComboBoxControl"
        Label = "{Binding ElementName=MCB, Path=Label}"
        ItemsSource="{Binding ElementName=MCB, Path=ItemsSource}"
        SelectedItem="{Binding ElementName=MCB, Path=SelectedItem}" />
    <Button x:Name="CreateItemButton"
        Grid.Column="1" Width="25" Margin="2,0,0,0"
        Content="+" FontFamily="Courier" FontSize="18" 
        VerticalContentAlignment="Center"
        Command="{Binding ElementName=MCB, Path=CreateItemCommand}"/>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)

这是它的代码隐藏:

public partial class MutableComboBox : UserControl
{
    public MutableComboBox()
    {
        InitializeComponent();
    }

    public string Label
    {
        get { return this.ComboBoxControl.Label; }
        set { this.ComboBoxControl.Label = value; }
    }

    #region ItemsSource dependency property
    public static readonly DependencyProperty …
Run Code Online (Sandbox Code Playgroud)

wpf user-controls command button

4
推荐指数
1
解决办法
1万
查看次数

Autofac参数传递和自动装配

无法理解在Autofac中传递的参数,以下代码不起作用:

class Config {
    public Config(IDictionary<string, string> conf) {}
}

class Consumer {
    public Consumer(Config config) {}
}

void Main()
{
    var builder = new Autofac.Builder.ContainerBuilder();
    builder.Register<Config>();
    builder.Register<Consumer>();
    using(var container = builder.Build()){
        IDictionary<string,string> parameters = new Dictionary<string,string>();
        var consumer = container.Resolve<Consumer>(Autofac.TypedParameter.From(parameters));
    }
}
Run Code Online (Sandbox Code Playgroud)

抛出:

DependencyResolutionException: The component 'UserQuery+Config' has no resolvable constructors. Unsuitable constructors included:
Void .ctor(System.Collections.Generic.IDictionary`2[System.String,System.String]): parameter 'conf' of type 'System.Collections.Generic.IDictionary`2[System.String,System.String]' is not resolvable.
Run Code Online (Sandbox Code Playgroud)

但以下代码确实有效:

IDictionary<string,string> parameters = new Dictionary<string,string>();
var config = container.Resolve<Config>(Autofac.TypedParameter.From(parameters));
var consumer = …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection autofac

6
推荐指数
1
解决办法
8533
查看次数

可以通过foreach向后迭代?

我知道我可以使用一个for语句并实现相同的效果,但是我可以foreach在C#中循环回循环吗?

c# foreach

117
推荐指数
7
解决办法
14万
查看次数

标签栏控制器(iphone)

我正在制作标签栏的应用...有5个tabbars.ie主页,询问,提示,收件箱,免责声明..现在问题是我希望控件在应用程序启动后直接转移到免责声明标签.现在控制转移到主页选项卡...这是第一个选项卡

iphone xcode objective-c

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

Linq到NHibernate与ICriteria

我一般使用LINQ,特别是LINQ-to-Objects,因此我对LINQ非常流利.

我正在考虑使用LINQ-to-NHibernate作为我的NHibernate项目的查询语言.当我写一些测试时,我注意到LINQ-to-NHibernate没有和ICriteria做同样的查询.因为我更喜欢使用LINQ,所以我想问一下是否有人知道类似的差异,或者我是否应该一般不关心性能(无论如何,高性能操作都需要对NHibernate进行一些调整.它).请参阅以下示例:

var query = (from inputItem in session.Linq<InputItem>()
             where inputItem.Project == project select inputItem).First();
Run Code Online (Sandbox Code Playgroud)

给我以下SQL:

SELECT this_.ID as ID0_1_, this_.Name as Name0_1_, this_.Project_id as Project3_0_1_, project1_.ID as ID1_0_, project1_.Name as Name1_0_
    FROM "InputItem" this_ left outer join "Project" project1_ on this_.Project_id=project1_.ID
    WHERE this_.Project_id = @p0 limit 1;@p0 = 1, @p1 = 1
Run Code Online (Sandbox Code Playgroud)

var criteria = session.CreateCriteria<InputItem>();
criteria.Add(Expression.Eq("Project", project));
criteria.SetMaxResults(1);
criteria.List();
Run Code Online (Sandbox Code Playgroud)

SELECT this_.ID as ID0_0_, this_.Name as Name0_0_, this_.Project_id as Project3_0_0_
    FROM "InputItem" this_
    WHERE this_.Project_id = @p0 …
Run Code Online (Sandbox Code Playgroud)

linq nhibernate c#-3.0

5
推荐指数
1
解决办法
1786
查看次数

如何使用XStream框架编码UTF-8?

根据XStream的FAQ,它的默认解析器不保留UTF-8文档编码,并且必须提供自己的编码器.怎么做到这一点?

谢谢!

xml encode xstream utf-8

14
推荐指数
2
解决办法
2万
查看次数

整个网站上的SSL还是其中的一部分?

我有一个网站......让我们称之为mysite.com.在这个网站上,有一个注册部分,我认为应该是这个网站的安全部分.

a)我应该在整个网站上启用ssl,还是只注册注册部分(例如signup.mysite.com)b)为整个网站启用它的优缺点是什么?

security ssl

9
推荐指数
3
解决办法
9140
查看次数

我们应该使用Path.DirectorySeperatorChar C#

现在一个潜藏在我脑海中的问题.Path.DirectorySeperatorChar的重要性是什么?我的意思是我们不能只改为'\' - 我认为这比调用属性更快,特别是如果你在应用程序中构建了大量的路径?有原因吗?除了'\'之外,文件夹/文件路径分离是否还有其他字符?也许在另一个操作系统?

.net c# string

4
推荐指数
1
解决办法
497
查看次数