• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 19:10
CEST 01:10
KST 08:10
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris34Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
BoxeR's Wings Episode 2 - Fan Translation Greatest Players of All Time: 2025 Update #1: Maru - Greatest Players of All Time A Eulogy for the Six Pool Geoff 'iNcontroL' Robinson has passed away
Tourneys
$5,000 WardiTV Summer Championship 2025 Maestros of The Game—$20k event w/ live finals in Paris $5,100+ SEL Season 2 Championship (SC: Evo) Esports World Cup 2025 Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Post ASL20 Ro24 discussion. No Rain in ASL20? How do I speak directly to Coinbase?1-(888)-419-97 Recent recommended BW games
Tourneys
[ASL20] Ro24 Group D [ASL20] Ro24 Group E Small VOD Thread 2.0 [Megathread] Daily Proleagues
Strategy
Muta micro map competition Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Stormgate/Frost Giant Megathread General RTS Discussion Thread Nintendo Switch Thread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Customize Sidebar...

Website Feedback

Closed Threads



Active: 967 users

The Big Programming Thread - Page 209

Forum Index > General Forum
Post a Reply
Prev 1 207 208 209 210 211 1031 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
mustache
Profile Joined April 2010
Switzerland309 Posts
December 05 2012 08:45 GMT
#4161
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic
Sub40APM
Profile Joined August 2010
6336 Posts
December 05 2012 09:25 GMT
#4162
On December 04 2012 06:48 Blisse wrote:

For example, if you call lower() on a string, then you check if the string has any uppercase letters. It even sounds redundant, no? as how can a lower cased string have uppercase letters anyways?

I agree with most of your post but must come to his defense. If you look back to his code, while he converts the input string into lower and does stuff to it, his check on Uppercase applies to the original input string, whatever it may be.
Arnstein
Profile Blog Joined May 2010
Norway3381 Posts
December 05 2012 10:33 GMT
#4163
Anyone know where I can find good exercises for double lists and matrices in Python?
rsol in response to the dragoon voice being heard in SCII: dragoon ai reaches new lows: wanders into wrong game
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
Last Edited: 2012-12-05 10:53:57
December 05 2012 10:47 GMT
#4164
I'm heavy into C++ and .NET but I need to learn some PHP+mySQL. Are there any good advanced tutorial sites out there? As in, they don't have to explain all the programming basics, just the language itself and the environment to work in. I have never developed in a web language so I'm new in that specific area.

Also what good free IDEs are there for php?
England will fight to the last American
AmericanUmlaut
Profile Blog Joined November 2010
Germany2577 Posts
December 05 2012 11:28 GMT
#4165
On December 05 2012 19:47 KaiserJohan wrote:
Also what good free IDEs are there for php?

I use NetBeans for PHP and it works very well.
The frumious Bandersnatch
KaiserJohan
Profile Joined May 2010
Sweden1808 Posts
December 05 2012 11:36 GMT
#4166
What about the eclipse PHP plugins?
England will fight to the last American
Kambing
Profile Joined May 2010
United States1176 Posts
Last Edited: 2012-12-05 16:05:15
December 05 2012 14:17 GMT
#4167
On December 05 2012 17:41 ghrur wrote:
Hi guys,

So next semester, I will be learning Python as part of a Comp Sci class I'll be taking. At the end of the class, we'll have to make a project primarily in Python. I've heard about this from my friends who're taking it now, so I've started contemplating the project. One of the thoughts I had was making an AI of sorts to play BW. It'd probably work through BWAPI. The problem is, a lot of my friends also say Python is too slow to be able to make the calculations for a game AI.

Anyway, I'd just like some opinions on if it'd be possible to build a BW AI-bot in python.

Thanks!


It's perfectly reasonable; you aren't going to be building anything crazy performance-demanding.

The only catch is that the BWAPI library is written in C++ so you would need to understand how to interop with C++ code from Python. Luckily, someone's already written Python bindings against BWAPI, so you don't even need to worry about that:

http://code.google.com/p/bwapi/
http://code.google.com/p/pybw/
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 05 2012 14:28 GMT
#4168
On December 05 2012 17:45 mustache wrote:
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic


I came across the same problem before. I knew this ability existed, because if you've used a lot of terminal installers, they often have a static download bar. However, I never found out how to do this.

I would appreciate an answer to this problem as well, even though I've moved on.



On December 05 2012 18:25 Sub40APM wrote:
Show nested quote +
On December 04 2012 06:48 Blisse wrote:

For example, if you call lower() on a string, then you check if the string has any uppercase letters. It even sounds redundant, no? as how can a lower cased string have uppercase letters anyways?

I agree with most of your post but must come to his defense. If you look back to his code, while he converts the input string into lower and does stuff to it, his check on Uppercase applies to the original input string, whatever it may be.


Ooops. XD Strange that I missed that, though that would be another sample of redundancy, for this case.
Actually, now I'm deciding if it was wrong to get the Pig Latin of the lowercased word, though I'm not sure how abbreviations and proper nouns should be handled, because the words that would be created wouldn't be real words (though it's never a real word anyways).
There is no one like you in the universe.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-12-05 16:47:29
December 05 2012 16:46 GMT
#4169
On December 05 2012 17:41 ghrur wrote:
Hi guys,

So next semester, I will be learning Python as part of a Comp Sci class I'll be taking. At the end of the class, we'll have to make a project primarily in Python. I've heard about this from my friends who're taking it now, so I've started contemplating the project. One of the thoughts I had was making an AI of sorts to play BW. It'd probably work through BWAPI. The problem is, a lot of my friends also say Python is too slow to be able to make the calculations for a game AI.

Anyway, I'd just like some opinions on if it'd be possible to build a BW AI-bot in python.

Thanks!

A lot of your friends say Python is too slow for AI calculations? Sigh... A lot of your friends like to make assumptions without testing them. Python is perfectly fine for scripting AI. Your friends don't know what they're talking about.

On December 05 2012 17:45 mustache wrote:
I'm programming a small snake game in C that runs in the console window. right now it clears and redraws the entire screen every time the snake moves 1 increment. this make the bottom of the screen start flickering because the redraw at the bottom takes longer than the top.

my question is if there is a way to go to a specific line in the console window, delete that line, and redraw it. that way i could check if something changed and update only that line.

using windows and visual basic

That's weird, are you multi-threading at all? That sounds like screen tearing where you're calling WriteConsoleOutput too quickly. Are you at least double buffering? Here's a couple links, which should be way more than enough information for you to fix this:
http://cecilsunkure.blogspot.com/2011/11/windows-console-game-setting-up-window.html
http://cecilsunkure.blogspot.com/2012/07/windows-console-game-ascii-engine.html
mustache
Profile Joined April 2010
Switzerland309 Posts
Last Edited: 2012-12-05 18:26:41
December 05 2012 18:24 GMT
#4170
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch
Bigpet
Profile Joined July 2010
Germany533 Posts
December 05 2012 18:30 GMT
#4171
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


I don't know about the performance characteristics of system("cls") but you shouldn't printf() every single charater. You flush way too often that way. I'd advise you sprintf() a whole frame and just call printf() once you constructed the whole frame.
I'm NOT the caster with a similar nick
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
December 05 2012 18:34 GMT
#4172
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


It's not possible in default C as far as i remember, though there are libraries for that.
From a quick google, http://www.projectpluto.com/win32a.htm should work. I haven't tried it though since most of my C development was under linux where we had ncurses (which is not available for windows).
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
December 05 2012 18:37 GMT
#4173
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)
There is no one like you in the universe.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-12-05 18:51:27
December 05 2012 18:50 GMT
#4174
On December 06 2012 03:37 Blisse wrote:
Show nested quote +
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)


Yep, turns out this is one of those things Windows sucks at. This program would run as intended on a Unix box, because of how POSIX streams work. In any case, probably best practice to build your string first, then print it. It will make the code a bit more readable.

Also, sorry that you have to deal with windows command line :/


Any sufficiently advanced technology is indistinguishable from magic
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 05 2012 18:51 GMT
#4175
On December 06 2012 03:37 Blisse wrote:
Show nested quote +
On December 06 2012 03:24 mustache wrote:
+ Show Spoiler +

void Print_Field()
{
int i;
int h;
system("cls"); // clears old screen
printf("points: %d\n", points); // displays points in first console line
for(i=0, h=1; i<AREA; i++) // prints gamefield, until the array with size AREA is completely printed
{
if(i == h*WIDTH) // array is 1 dimensional ; program skips to a new line every time WIDTH has been reached
{
printf("\n");
h=h+1;
}
printf("%c", field[i].sprite); // chooses what character is printed

}
}


so im just cycling through my array and printing the values that are in that. but because the redrawing isnt fast enough the screen flickers(i assume)

I've just started out programming in general so im not sure what multi threading or double buffering is.(so im probably not using it)

ill check out the links in detail, but i'd like to program the game from start to finish by my self, to get more familiar with how things work.

EDIT: i noticed in my first post i wrote im using visual basic. I meant visual studio c++, and im coding in C. ouch


Could you try building the array as a giant string, and then calling printf once on that entire string? That should solve it.


@Cecil, I think he's writing a literal basic Console program, not a WIN32 application that interfaces with the Console. XD (even though it's kinda a subset of the other)


Oh I see, haha. Yeah just use a single printf call. The screen might "flicker" a little when the console scrolls. You can change the height in characters of the console so that it cannot scroll, if you wanted to.
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-05 18:53:05
December 05 2012 18:52 GMT
#4176
Could somebody explain to me whilst keeping terminology to a minimum what Indendation(Python) actually does. I keep coding and doing stuff but this is something I keep wondering about. My guess is that it separates things.
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
Last Edited: 2012-12-05 18:55:33
December 05 2012 18:55 GMT
#4177
On December 06 2012 03:52 Recognizable wrote:
Could somebody explain to me whilst keeping terminology to a minimum what Indendation(Python) actually does. I keep coding and doing stuff but this is something I keep wondering about. My guess is that it separates things.

It creates a new scope every time you indent. The scope closes when the indent is de-indented.
mustache
Profile Joined April 2010
Switzerland309 Posts
December 05 2012 18:59 GMT
#4178
Ok thanks, ill try using a single string, though on my first try the game start crashing :D ill have to give it another go


btw here the code if anyone's interested, and wants to see the flickering.
+ Show Spoiler +
#include <stdio.h>
#include <conio.h>
#include <Windows.h>
#include <time.h>

/**************************************************************************************************************/
#define HEIGHT (24)
#define WIDTH (50)
#define AREA (HEIGHT*WIDTH)
#define MAX_LENGTH (40)
//#define LENGTH (30)
#define RIGHT ('d')
#define LEFT ('a')
#define UP ('w')
#define DOWN ('s')


/**************************************************************************************************************/
struct position // structure prototype for positions in array
{
int x;
int y;
char sprite;
};

struct position field[AREA]; // gamefield array
struct position snake[MAX_LENGTH]; // snake body array
struct position snake_temp[MAX_LENGTH]; // temp snake array copy
struct position fruit;
char input = RIGHT;
int SPEED = 5;
int points = 0;
int LENGTH = 1;
char buffer[AREA+1];
/**************************************************************************************************************/
int Game_Menu();
int Sub_Menu();
void Field_Set();
void Print_Field();
int Snake_Set();
void Snake_Input();
void Snake_Init();
void Menu();
void Fruit_Gen();
void Fruit_Set();
/**************************************************************************************************************/

int main()
{
int game_loop = 1;
int main_loop = 1;
srand(time(NULL));

while(main_loop ==1)
{
Game_Menu();

game_loop = 1;
while (game_loop == 1)
{
Snake_Input();
Field_Set();
Fruit_Set();
game_loop = Snake_Set();
Print_Field();
}
}
return 0;
}

int Game_Menu()
{
int menu = 1;
int game_loop;
char menu_input = 'o';


while( menu == 1)
{
Menu();
menu_input = getch();
menu = Sub_Menu(menu_input);
}

system("cls");
return 0;
}
void Menu()
{
system("cls");
printf("*******************************************************************************\n");
printf("* ***** * * ***** * * **** *\n");
printf("* * ** * * * * * * *\n");
printf("* ***** * * * ***** * ** *\n");
printf("* * * ** * * * * * *\n");
printf("* ***** * * * * * * **** *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* SET SPEED OPTIONS[s] SET OBSTACLE OPTIONS[o] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* START GAME[y] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* exit[x] *\n");
printf("*******************************************************************************\n");
}
int Sub_Menu(char menu_input)
{
int output = 1;
char set_char = 'z';

switch(menu_input)
{
case 's':
system("cls");
printf("*******************************************************************************\n");
printf("* ***** * * ***** * * **** *\n");
printf("* * ** * * * * * * *\n");
printf("* ***** * * * ***** * ** *\n");
printf("* * * ** * * * * * *\n");
printf("* ***** * * * * * * **** *\n");
printf("* DIFFICULTY SETTINGS *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* HARD[h] EASY[e] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* MIDDLE[m] *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* *\n");
printf("* exit[x] *\n");
printf("*******************************************************************************\n");

while(set_char != 'm' && set_char != 'e' && set_char != 'h')
{
set_char = getch();
}
switch(set_char)
{
case 'e':
SPEED = 100;
break;
case 'm':
SPEED = 5;
break;
case 'h':
SPEED = 0;
}
break;
case 'o':
printf("you are in obstacle menu");
break;
case 'y':
output = 0;
Snake_Init();
break;
case 'x':
printf("you exited the game");
break;
}

return output;
}

void Field_Set()
{
int i,h;// counter variable




for(i = 0, h=0; i< AREA;i++)// writes x and y coordinates into gamefield array
{

field[i].x = i%WIDTH;
field[i].y = i/WIDTH;
}


for(i = 0; i< AREA; i++)// writes boundarys into gamefield
{
if(field[i].x == 0 || field[i].x == (WIDTH-1) || field[i].y == 0 || field[i].y == (HEIGHT-1))
{
field[i].sprite = '*'; // boundary
}
else
{
field[i].sprite = ' '; // empty space
}
}
}

void Print_Field()
{
int i;
int h;
system("cls");
printf("points: %d\n", points);
for(i=0, h=1; i<AREA; i++) // prints gamefield
{
if(i == h*WIDTH)
{
printf("\n");

h=h+1;
}
printf("%c", field[i].sprite);

}


}

int Snake_Set()
{
int game_loop = 1;
int i;

for(i=0;i<LENGTH;i++)
{
if(field[snake[i].x + snake[i].y*WIDTH].sprite == '*' ||field[snake[i].x + snake[i].y*WIDTH].sprite == 'X')
{
Beep(500,500);
game_loop = 0;
}
else if(field[snake[i].x + snake[i].y*WIDTH].sprite == 'O')
{
points = points + 10;
if(LENGTH < MAX_LENGTH-1)
{
LENGTH = LENGTH +1;
}
Fruit_Gen();
Beep(500,30);
Beep(400,100);
}
else
{
field[snake[i].x+ snake[i].y*WIDTH].sprite = '*';
}
}
return game_loop;
}

void Snake_Input() // DONT FORGET TO SET THE DIRECTION TO AN INITIAL VALUE
{
int i;
int temp_input;


for(i=0; i<1; i++)
{
if(kbhit() == 1)
{
temp_input = getch();

if(temp_input == RIGHT || temp_input == LEFT || temp_input == UP ||temp_input == DOWN)
{
input = temp_input;
}
}
else
{
Sleep(SPEED);
}
}
for(i=0; i<LENGTH; i++) // copies snake into a temp snake array, and increase the positions
{
snake_temp[i].x = snake[i].x;
snake_temp[i].y = snake[i].y;
}

for(i=0;i<LENGTH;i++)
{
snake[i+1].x = snake_temp[i].x;
snake[i+1].y = snake_temp[i].y;
}


switch(input)
{
case RIGHT:
snake[0].x = snake[0].x + 1;
break;
case LEFT:
snake[0].x = snake[0].x - 1;
break;
case UP:
snake[0].y = snake[0].y - 1;
break;
case DOWN:
snake[0].y = snake[0].y + 1;
break;
}
}

void Snake_Init()
{
int i;
Fruit_Gen();
points = 0;
LENGTH = 1;
for(i = 0; i<MAX_LENGTH;i++)
{
snake[i].x = WIDTH/2-i;
snake[i].y = HEIGHT/2;
}
}

void Fruit_Gen()
{
int random_x;
int random_y;
int fruit_loop = 1;

while(fruit_loop == 1)
{
random_x = rand()%(WIDTH/2+1);
random_y = rand()%(HEIGHT/2+1);
if(random_x != 0 && random_x != WIDTH && random_y != 0 && random_y != HEIGHT)
{
fruit_loop = 0;
fruit.x = random_x;
fruit.y = random_y;
}
}
}

void Fruit_Set()
{
field[fruit.x+ fruit.y*WIDTH].sprite = 'O';
}
Recognizable
Profile Blog Joined December 2011
Netherlands1552 Posts
Last Edited: 2012-12-05 19:06:29
December 05 2012 19:06 GMT
#4179
I had to search for what scope is but I guess I understand it a bit better now. Why is this important? Why doesn't the computer understand what you are doing when you aren't indenting?

def f(a,b):
c = a + b
c = g(c) + X
d = c * c + a
return d * b


Am I right in saying that this works because return is in the same scope as C,D and so it can do something with these variables. If return wasn't indented it wouldn't be able to do that because it wasn't in the same scope and therefore can't do anything with those variables?
CecilSunkure
Profile Blog Joined May 2010
United States2829 Posts
December 05 2012 19:10 GMT
#4180
On December 06 2012 04:06 Recognizable wrote:
I had to search for what scope is but I guess I understand it a bit better now. Why is this important? Why doesn't the computer understand what you are doing when you aren't indenting?

def f(a,b):
c = a + b
c = g(c) + X
d = c * c + a
return d * b


Am I right in saying that this works because return is in the same scope as C,D and so it can do something with these variables. If return wasn't indented it wouldn't be able to do that because it wasn't in the same scope and therefore can't do anything with those variables?

Yeah that's right. When you make something within a scope, things outside of that scope cannot access the variable. It's not about the computer "knowing what you are doing", the Python interpreter is just following rules the creator laid out. Scoping is a good thing.

If there was no scoping (or another way to say this is if there were only the global scope) then you could only have one name to one identifier. This gets annoying when you want to reuse an identifier.


for i in range( 0, 10 ):
print( i )

for x in range( 0, 10 ):
print( x )


You can see here I've already used two different identifiers, x and i. Luckily those two variables are within the scope of the for loops, otherwise I'd have to use a different variable name for each loop.
Prev 1 207 208 209 210 211 1031 Next
Please log in or register to reply.
Live Events Refresh
Next event in 50m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ProTech122
CosmosSc2 57
StarCraft: Brood War
Aegong 978
Artosis 649
scan(afreeca) 37
Purpose 11
Counter-Strike
Stewie2K721
taco 410
Foxcn293
Other Games
summit1g7478
tarik_tv3691
Grubby2272
FrodaN2117
Sick355
C9.Mang0195
ViBE194
shahzam181
ToD175
Day[9].tv91
Mew2King48
PPMD31
Organizations
Other Games
BasetradeTV23
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 18 non-featured ]
StarCraft 2
• RyuSc2 47
• musti20045 35
• IndyKCrew
• Migwel
• sooper7s
• AfreecaTV YouTube
• intothetv
• Kozan
• LaughNgamezSOOP
StarCraft: Brood War
• Pr0nogo 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21937
League of Legends
• Doublelift4268
Counter-Strike
• Shiphtur172
Other Games
• imaqtpie1000
• Day9tv91
Upcoming Events
Replay Cast
50m
LiuLi Cup
11h 50m
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
16h 50m
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
Big Brain Bouts
16h 50m
Iba vs GgMaChine
TriGGeR vs Bunny
Reynor vs Classic
Serral vs Clem
BSL Team Wars
19h 50m
Team Hawk vs Team Dewalt
BSL Team Wars
19h 50m
Team Hawk vs Team Bonyth
Code For Giants Cup
23h 20m
SC Evo League
1d 12h
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
1d 16h
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[BSL 2025] Weekly
1d 18h
[ Show More ]
SC Evo League
2 days
Maestros of the Game
2 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
2 days
Team Bonyth vs Team Sziky
BSL Team Wars
2 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
3 days
Replay Cast
4 days
Sparkling Tuna Cup
4 days
LiuLi Cup
5 days
Replay Cast
6 days
The PondCast
6 days
RSL Revival
6 days
Maru vs SHIN
MaNa vs MaxPax
Liquipedia Results

Completed

CSL Season 18: Qualifier 1
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.