我目前正在编写一个需要频繁比较字符串长度的C程序,所以我编写了以下辅助函数:
int strlonger(char *s1, char *s2) {
return strlen(s1) - strlen(s2) > 0;
}
Run Code Online (Sandbox Code Playgroud)
我注意到,即使s1长度比短,函数返回true s2.有人可以解释这种奇怪的行为吗?
我正在寻找有关笛卡尔几何或基于坐标的游戏编程的一些基础知识.平台是无关紧要的,虽然我最精通JavaScript,C,Objective-C.最终能够创造诸如点或棋子之类的东西将是理想的.我的想法是让我了解精灵的工作原理以及路径如何以编程方式工作.我向你们提出的问题是,学习基础知识的最佳位置在哪里?一些不是数学的东西,因为坦率地说,在这一点上比微积分更先进的东西是灰线,需要刷新我的记忆.
如果有特定的书籍,网站或开源项目 - 这可能对我有用.
谢谢你的任何想法.
所以基本上我有一个GridWorld项目,我现在正在AP Comp Sci课程中做.我在做Pacman.这是我的act方法的代码(对于那些不熟悉GridWorld的人来说,每当一个actor需要做一个新的动作时都会调用act方法):
public void act()
{
Location loc = getLocation();
if(direction==null) {
}
else if(direction.equals("NORTH")) {
Location next = loc.getAdjacentLocation(loc.NORTH);
if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
if(getGrid().get(next) instanceof Food)
addFood();
moveTo(next);
direction = "NORTH";
}
}
else if(direction.equals("SOUTH")) {
Location next = loc.getAdjacentLocation(loc.SOUTH);
if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
if(getGrid().get(next) instanceof Food)
addFood();
moveTo(getLocation().getAdjacentLocation(getLocation().SOUTH));
direction = "SOUTH";
}
}
else if(direction.equals("EAST")) {
Location next = loc.getAdjacentLocation(loc.EAST);
if(getGrid().isValid(next) && (getGrid().get(next)==null || getGrid().get(next) instanceof Food)) {
if(getGrid().get(next) …Run Code Online (Sandbox Code Playgroud)