Move up one line in console (Pascal) - console

I'm sitting at college making a noughts and crosses game while everyone else is learning the basics of Pascal. I can print the 2D array denoting the board into the terminal just fine, but what I want to do is update the board everytime a player adds a nought or cross, or moves their cursor around. To do this, I want to over-write the old board with the new one. Is there a way to move the console cursor up one line (Windoze console by the way), or can I clear the entire terminal in Pascal?
Thanks,
James
Ps. This is NOT homework.

Depending on what flavour of Pascal you are using you may be able to use gotoxy(). Typically this will be in a Pascal UNIT such as CRT, so you'll need a USES CRT; at the start of your program, e.g.
PROGRAM main;
USES CRT;
BEGIN
gotoxy(10, 10);
writeln('Hello world!');
END.

Related

Use KinematicBody2D as RigidBody2D

Hello, I'm new on Godot (I'm French, that's why my English is not perfect)
I'm trying to create a game (top down) where the principle is the same as a Sumo fight, take out your opponent outside a circle. The problem that I met is that if I use KinematicBody2D the characters don't push each other which is the base of the game, I saw then that it could be possible with RigidBody2D but I can't find any way on internet to make it move like this : https://docs.godotengine.org/fr/stable/tutorials/2d/2d_movement.html#rotation-movement . I then searched if it was possible to push a KinematicBody2D with another KinematicBody2D (so that it can be pushed) but I also couldn't find any way.
So I'm stuck here, and my question is if this is possible and especially how I could do this?
Thanks for reading,
Noflare
I believe the issue here would be that you are not using collisions. The functions move_and_slide or move_and_collide would engage a Kinematic Body to move, and hit other bodies (including Kinematic Body).
However, as soon as you use either function you will realise they don't push each other in the way you need in the question.
From the docs (en, fr)
move_and_collide: The moving object will move and if there is a collider (any obstacle), it will stop immediately upon collision and return a KinematicCollision2D object.
move_and_slide: Takes further action compared to move_and_collide, the moving object will slide over the collider, treating it like a wall or a floor. Useful for platformer games.
In your use case, you have no choice but to control the collision yourself. You can get more info here on KinematicCollision2D here: (en, fr). This could be possibly how you do it:
var collision = player.move_and_collide(direction_vector)
if (!collision):
# No collision occurred
return
else:
# Collided with a wall or player
if (collision.collider == wall)
# if you keep track of wall object as a variable to identify it
# you can have the sumo just stop moving and not process anymore
return
else:
var opponent = collision.collider
# write game logic to move opponent and yourself
return

How can I make a program wait in OCaml?

I'm trying to make a tetris game in ocaml and i need to have a piece move through the graphics screen at a certain speed.
I think that the best way to do it is to make a recursive function that draws the piece at the top of the screen, waits half a second or so, clears that piece from the screen and redraws it 50 pixels lower. I just don't know how to make the programm wait. I think that you can do it using the Unix module but idk how..
Let's assume you want to take a fairly simple approach, i.e., an approach that works without multi-threading.
Presumably when your game is running it spends virtually all its time waiting for input from the user, i.e., waiting for the user to press a key. Most likely, in fact, you're using a blocking read to do this. Since the user can take any amount of time before typing anything (up to minutes or years), this is incompatible with keeping the graphical part of the game up to date.
A very simple solution then is to have a timeout on the read operation. Instead of waiting indefinitely for the user to press a key, you can wait at most (say) 10 milliseconds.
To do this, you can use the Unix.select function. The simplest way to do this is to switch over to using a Unix file descriptor for your input rather than an OCaml channel. If you can't figure out how to make this work, you might come back to StackOverflow with a more specific question.

How can the processor discern a far return from a near return?

Reading Intel's big manual, I see that if you want to return from a far call, that is, a call to a procedure in another code segment, you simply issue a return instruction (possibly with an immediate argument that moves the stack pointer up n bytes after the pointer popping).
This, apparently, if I'm interpreting things correctly, is enough for the hardware to pop both the segment selector and offset into the correct registers.
But, how does the system know that the return should be a far return and that both an offset AND a selector need to be popped?
If the hardware just pops the offset pointer and not the selector after it, then you'll be pointing to the right offset but wrong segment.
There is nothing special about the far return command compared to the near return version.
They both look identical as far as I can tell.
I assume then that the processor, perhaps at the micro-architecture level, keeps track of which calls are far and which are close so that when they're returned from, the system knows how many bytes to pop and where to pop them (pointer registers and segment selector registers).
Is my assumption correct?
What do you guys know about this mechanism?
The processor doesn't track whether or not a call should be far or near; the compiler decides how to encode the function call and return using either far or near opcodes.
As it is, FAR calls have no use on modern processors because you don't need to change any segment register values; that's the point of a flat memory model. Segment registers still exist, but the OS sets them up with base=0 and limit=0xffffffff so just a plain 32-bit pointer can access all memory. Everything is NEAR, if you need to put a name on it.
Normally you just don't even think about segmentation so you don't actually call it either. But the manual still describes the call/ret opcodes we use for normal code as the NEAR versions.
FAR and NEAR were used on old 86 processors, which used a segmented memory model. Programs at that time needed to choose what kind of architecture they wished to support, ranging from "tiny" to "large". If your program was small enough to fit in a single segment, then it could be compiled using NEAR calls and returns exclusively. If it was "large", the opposite was true. For anything in between, you had power to choose whether local functions needed to be able to be either callable/returnable from code in another segment.
Most modern programs (besides bootloaders and the like) run on a different construct: they expect a flat memory model. Behind the scenes the OS will swap out memory as needed (with paging not segmentation), but as far as the program is concerned, it has its virtual address space all to itself.
But, to answer your question, the difference in the call/return is the opcode used; the processor obeys the command given to it. If you mistake (say, give it a FAR return opcode when in flat mode), it'll fail.

QT QAudiooutput only playing through left ear while in stereo

What i have currently is an attempt to have a signal generator play in stereo. What is currently happening is while the format has been accepted it winds up only playing the audio from the left ear. However when i switch to mono it works fine through both ears however what i want to do is have it where i can control which ear i am listening from. For instance if i only want it to play on the left ear all i will hear is the audio on the left ear, however i also want to ability to switch ears or use both. The current method i am using is as follows.
format.setFrequency(44100);
format.setChannels(2);
format.setSampleSize(16);
format.setCodec("audio/pcm");
format.setByteOrder(QAudioFormat::LittleEndian);
format.setSampleType(QAudioFormat::SignedInt);
//This is just the format setup.
// i am using push mode for this program
audio_outputStream = new QAudioOutput(format, this);
audio_outputDevice = audio_outputStream->start();
//now when i write the numbers from the signal generator i use this method
QByteArray array;
array.append(integerValueThatIsConvertedToConstChar,SizeOfInt);
//And i write the data from the ByteArray to the IODevice as such
audio_outputDevice.write(array.data(),MaxSizeOfInt);
//Afterwhich i remove the front of the ByteArray for the next number to be appended and wrote in.
array.remove(0,SizeOfInt);
As stated before the above steps i use in my code do work with monotone with one channel but only plays on the left side when using Stereo with 2 channels. My goal is to be able to control which channel i am writing to through push mode. I currently do not see why it currently only uses one of the two channels, am I simply not writing to the second channel?

multinote instruments and chords

I am new in ableton live software. I would like to understand why for some instruments I can play several notes at the same time (and create chord progression) and for the others I can hear only one note of a chord.
For example, there are two guitars: 'Power Chords Guitar' and 'Please Rise For Jimi Guitar'. Both of them are basing on an operator. For the first one I am able to press several buttons on midi keyboard and hear a sound, for the second I can hear only one note of a chord.
I was trying to compare operator options, but I was unable to find the setting which causes this multinote/mononote functionality.
Thank you very much for your help.
J
Ableton's Operator consists of 4 monophonic oscillators. Depending on a preset, it can be setup to play polyphony. It seems that the Glide function is responsible for that effect. Make sure you have at least 2 oscillators (the more the more poly) with Glide "on" set.
Check out Ableton's webpage for reference on how to use its instruments.

Resources