feat: add guessing example
This commit is contained in:
parent
547c5d0c63
commit
0ced372a77
3 changed files with 31 additions and 2 deletions
|
@ -31,7 +31,8 @@ ToDo List:
|
||||||
- [ ] add inclusive operators like '!=', '>=', '<='
|
- [ ] add inclusive operators like '!=', '>=', '<='
|
||||||
- [ ] add support for priority operators
|
- [ ] add support for priority operators
|
||||||
- [X] add input_number() std function
|
- [X] add input_number() std function
|
||||||
- [ ] add type() std function
|
- [ ] add null type (dirty way to handle no returns and some errors)
|
||||||
|
- [ ] add type() std function and others type checking functions
|
||||||
- [X] add ceil() and floor() std functions
|
- [X] add ceil() and floor() std functions
|
||||||
- [X] base of the CLI
|
- [X] base of the CLI
|
||||||
- [ ] evaluate expression from stdin
|
- [ ] evaluate expression from stdin
|
||||||
|
@ -149,6 +150,7 @@ floor(nb)
|
||||||
random_int(min, max)
|
random_int(min, max)
|
||||||
random_float(min, max)
|
random_float(min, max)
|
||||||
type(var) -> return the type of a var as int
|
type(var) -> return the type of a var as int
|
||||||
|
is_null(var)
|
||||||
is_int(var)
|
is_int(var)
|
||||||
is_float(var)
|
is_float(var)
|
||||||
print_string(str)
|
print_string(str)
|
||||||
|
|
23
examples/guessing.ltor
Normal file
23
examples/guessing.ltor
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
set i to 0
|
||||||
|
set toGuess to random_int(0, 100)
|
||||||
|
while 1 do
|
||||||
|
set guessed to input_number()
|
||||||
|
if i > 20 then
|
||||||
|
# do you really want to continue?
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if guessed = toGuess then
|
||||||
|
# success
|
||||||
|
print_ascii(83)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
if guessed < toGuess then
|
||||||
|
# too low
|
||||||
|
print_ascii(76)
|
||||||
|
end
|
||||||
|
if guessed > toGuess then
|
||||||
|
# too high
|
||||||
|
print_ascii(72)
|
||||||
|
end
|
||||||
|
set i to i+1
|
||||||
|
end
|
|
@ -134,7 +134,11 @@ int input_number_impl(int* res, unsigned char* resType, unsigned char* types, in
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
// we didn't manage to parse the number
|
||||||
|
*resType = TYPE_INT;
|
||||||
|
*res = 0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int simple_float_func(float (*func)(float), int* res, unsigned char* resType, unsigned char* types, int* args)
|
int simple_float_func(float (*func)(float), int* res, unsigned char* resType, unsigned char* types, int* args)
|
||||||
|
|
Loading…
Reference in a new issue