基本上我有一些类型船的结构,它们将放在可以具有可变宽度和高度的板上.有关船只的信息是从文件中读取的,我只需要知道确保没有任何船只重叠的最佳方法.
这是Ship的结构:
int x // x position of first part of ship
int y // y position of first part of ship
char dir // direction of the ship, either 'N','S','E' or 'W'
int length // length of the ship
Run Code Online (Sandbox Code Playgroud)
此外,处理方向的好方法是什么.比使用switch语句更清洁,并为每个方向使用不同的条件.
任何帮助将不胜感激!
我正在为'Room'类创建一个初始化函数,并发现该程序不接受我对输入变量进行的测试.
为什么是这样?
def __init__(self, code, name, type, size, description, objects, exits):
self.code = code
self.name = name
self.type = type
self.size = size
self.description = description
self.objects = objects
self.exits = exits
#Check for input errors:
if type(self.code) != type(str()):
print 'Error found in module rooms.py!'
print 'Error number: 110'
elif type(self.name) != type(str()):
print 'Error found in module rooms.py!'
print 'Error number: 111'
elif type(self.type) != type(str()):
print 'Error found in module rooms.py!'
print 'Error number: 112'
elif type(self.size) …Run Code Online (Sandbox Code Playgroud) 是否有MySQL命令来定位my.cnf配置文件,类似于PHP的phpinfo() 定位方式php.ini?
我目前在Drupal 6安装上使用统计模块(核心).每次查看节点时,这会增加{node_counter}表中的计数,这是有效的.
我的问题是 - 我可以通过编程方式递增此计数器吗?我希望当用户与从视图创建的内容(例如点击灯箱)进行交互时实现这一点,因此能够使用AJAX更新表格将是理想的选择.
我已经做了快速搜索,并且似乎没有任何模块可以立即发布.有人对这个有经验么?
MySQL慢查询日志通常按顺序显示以下一些条目.
SET timestamp=1268999330;
commit;
# User@Host: username[username] @ localhost []
# Query_time: 4.172700 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1268999330;
commit;
# User@Host: username[username] @ localhost []
# Query_time: 3.628924 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
SET timestamp=1268999330;
commit;
# User@Host: username[username] @ localhost []
# Query_time: 3.116018 Lock_time: 0.000000 Rows_sent: 0 Rows_examined: 0
...
Run Code Online (Sandbox Code Playgroud)
通常按顺序进行6-7"提交"查询.任何人他们是什么,以及他们每个人的先前查询是什么?
提前致谢.
我想知道内核如何为简单的C程序提供内存.
例如 :
#include<stdio.h>
#include<malloc.h>
int my_global = 10 ;
main()
{
char *str ;
static int val ;
str = ( char *) malloc ( 100 ) ;
scanf ( "%s" , str ) ;
printf( " val:%s\n",str ) ;
free(str) ;
return 1 ;
}
Run Code Online (Sandbox Code Playgroud)
看,在这个程序中我使用静态,全局和malloc来分配动态内存那么,内存的布局将是......?任何人给我的网址,其中将包含有关此过程的详细信息..
我有一堆C代码,我想使用Python的unittest库(在Windows中)进行单元测试,但我正在尝试找出连接C代码的最佳方法,以便Python可以执行它(和得到结果).有没有人以最简单的方式做到这一点?
一些想法包括:
这样做有规范的方法吗?我将使用不同的C模块进行相当多的操作,所以我想找到一种最省力的方法.
我正在制作一个自定义SQLite包装器.这意味着允许与数据库的预先连接.但是,我在调用此函数两次时收到异常.
public Boolean DatabaseConnected(string databasePath)
{
bool exists = false;
if (ConnectionOpen())
{
this.Command.CommandText = string.Format(DATABASE_QUERY);
using (reader = this.Command.ExecuteReader())
{
while (reader.Read())
{
if (string.Compare(reader[FILE_NAME_COL_HEADER].ToString(), databasePath, true) == 0)
{
exists = true;
break;
}
}
reader.Close();
}
}
return exists;
}
Run Code Online (Sandbox Code Playgroud)
我在执行命令或尝试打开数据库之前使用上面的函数来检查数据库当前是否已打开.第一次执行该函数时,它执行没有问题.之后reader = this.Command.ExecuteReader()抛出异常
Object reference not set to an instance of an object.
StackTrace:
at System.Data.SQLite.SQLiteStatement.Dispose()
at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteReader()
at …Run Code Online (Sandbox Code Playgroud) 在典型的业务应用程序中,拥有用于搜索的表单是很常见的.
一些基本功能是:
您希望在业务应用程序的搜索功能中还有哪些其他功能?
我正在尝试在不同的iPhone上运行的两个相同的应用程序之间进行一些图像编辑同步.我想将NSSet*从一个设备发送到另一个设备(我想这涉及封装在NSData中)然后将其解密回NSSet,然后在touchesMoved类型的函数中使用它.这是可行的,还是我应该同步UIImages?我担心UIImage同步对于实时交互会有太多的延迟.
谢谢你的帮助!