Welcome to RetroCoders Community
שלום;שלום! איך אני יכול לעזור לך היום?|מה שלומך?|היי, מה קורה?
מי אתה;אני צ'אטבוט שנוצר כדי לעזור לך.|אני תוכנת צ'אט.
default;אני מצטער אבל אני לא יודע מה לומר
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <locale.h>
#include <wchar.h>
#define MAX_KEYWORDS 100
#define MAX_RESPONSES 10
#define MAX_LINE_LENGTH 256
#define MAX_INPUT_LENGTH 100
typedef struct {
char keyword[MAX_INPUT_LENGTH];
char *responses[MAX_RESPONSES];
int response_count;
} KeywordResponse;
KeywordResponse database[MAX_KEYWORDS];
int keyword_count = 0;
HWND hwndInput;
HWND hwndButton;
HWND hwndOutput;
char *my_strdup(const char *str) {
size_t len = strlen(str) + 1;
char *dup = malloc(len);
if (dup != NULL) {
memcpy(dup, str, len);
}
return dup;
}
void load_database(const char *filename) {
FILE *file = fopen(filename, "r");
if (file == NULL) {
MessageBox(NULL, "Error: Could not open database file.", "Error", MB_ICONERROR | MB_OK);
exit(1);
}
char line[MAX_LINE_LENGTH];
while (fgets(line, sizeof(line), file) && keyword_count < MAX_KEYWORDS) {
line[strcspn(line, "\n")] = '\0'; // Remove the newline character if present
char *keyword = strtok(line, ";");
char *responses = strtok(NULL, "\n");
if (keyword && responses) {
strncpy(database[keyword_count].keyword, keyword, MAX_INPUT_LENGTH);
char *response = strtok(responses, "|");
while (response && database[keyword_count].response_count < MAX_RESPONSES) {
database[keyword_count].responses[database[keyword_count].response_count] = my_strdup(response);
database[keyword_count].response_count++;
response = strtok(NULL, "|");
}
keyword_count++;
}
}
// Add default reply to the database
strncpy(database[keyword_count].keyword, "default", MAX_INPUT_LENGTH);
database[keyword_count].responses[0] = my_strdup("אני לא מבין.");
database[keyword_count].response_count = 1;
fclose(file);
}
char *get_response(const char *input) {
for (int i = 0; i < keyword_count; i++) {
if (strstr(input, database[i].keyword)) {
int rand_index = rand() % database[i].response_count;
return database[i].responses[rand_index];
}
}
return get_response("default"); // If no keyword matches, return the default reply
}
void DisplayOutput(const wchar_t *output) {
int len = GetWindowTextLengthW(hwndOutput);
wchar_t *currentText = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
GetWindowTextW(hwndOutput, currentText, len + 1);
wchar_t *newText = (wchar_t *)malloc((len + wcslen(output) + 3) * sizeof(wchar_t));
wsprintfW(newText, L"%s\r\n%s", currentText, output);
SetWindowTextW(hwndOutput, newText);
free(currentText);
free(newText);
}
// Window procedure
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_CREATE: {
// Create input textbox
hwndInput = CreateWindowW(L"EDIT", L"",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
50, 300, 600, 25,
hwnd, NULL, NULL, NULL);
// Create talk button
hwndButton = CreateWindowW(L"BUTTON", L"דבר",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
670, 300, 80, 25,
hwnd, (HMENU)1, NULL, NULL);
// Create output textbox
hwndOutput = CreateWindowW(L"EDIT", L"",
WS_VISIBLE | WS_CHILD | WS_BORDER | ES_MULTILINE | ES_READONLY | WS_VSCROLL,
50, 50, 700, 200,
hwnd, NULL, NULL, NULL);
break;
}
case WM_COMMAND:
if (LOWORD(wParam) == 1) {
// Get text from input textbox
wchar_t wbuffer[MAX_INPUT_LENGTH];
GetWindowTextW(hwndInput, wbuffer, MAX_INPUT_LENGTH);
// Convert wchar_t to char
char input[MAX_INPUT_LENGTH];
wcstombs(input, wbuffer, MAX_INPUT_LENGTH);
// Get response
char *response = get_response(input);
// Convert response to wchar_t for display
wchar_t wresponse[MAX_LINE_LENGTH];
mbstowcs(wresponse, response, MAX_LINE_LENGTH);
// Display response and input
DisplayOutput(wbuffer);
DisplayOutput(wresponse);
// Clear input textbox and set focus
SetWindowTextW(hwndInput, L"");
SetFocus(hwndInput);
}
break;
case WM_KEYDOWN:
if (wParam == VK_RETURN) {
SendMessage(hwnd, WM_COMMAND, 1, 0);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
// Set locale to support Hebrew
setlocale(LC_ALL, "Hebrew_Israel.1255");
// Load the database
load_database("database.txt");
// Define and register the window class
const wchar_t CLASS_NAME[] = L"ChatbotWindowClass";
WNDCLASSW wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // Set background to white
RegisterClassW(&wc);
// Create the window
HWND hwnd = CreateWindowExW(
0,
CLASS_NAME,
L"צ'אטבוט",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 800, 400,
NULL,
NULL,
hInstance,
NULL);
if (hwnd == NULL) {
return 0;
}
// Show the window
ShowWindow(hwnd, nCmdShow);
// Message loop
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Free allocated memory for responses
for (int i = 0; i < keyword_count; i++) {
for (int j = 0; j < database[i].response_count; j++) {
free(database[i].responses[j]);
}
}
return msg.wParam;
}
#include <SDL\SDL.h>
#include <windows.h>
#include <math.h>
int WIDTH = 800;
int HEIGHT = 800;
long double min = -2.84;
long double max = 1.0;
long double factor = 1;
int MAX_ITERATIONS = 200;
long double map(long double value, long double in_min, long double in_max, long double out_min, long double out_max) {
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface* screen = SDL_SetVideoMode(1440, 900, 32, SDL_SWSURFACE);
if (!screen) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
SDL_Event event; // Declare event variable
int count = 0;
while (1) {
max -= 0.1 * factor;
min += 0.15 * factor;
factor *= 0.9349;
MAX_ITERATIONS += 5;
if (count > 30) {
MAX_ITERATIONS *= 1.02;
}
for (int x = 0; x < WIDTH; x++) {
for (int y = 0; y < HEIGHT; y++) {
// Move event handling inside the rendering loop
if (SDL_PollEvent(&event) && event.type == SDL_QUIT) {
SDL_Quit();
return 0;
}
if (GetKeyState('Q') & 0x8000) {
SDL_Quit();
return 0;
}
long double a = map(x, 0, WIDTH, min, max);
long double b = map(y, 0, HEIGHT, min, max);
long double ai = a;
long double bi = b;
int n = 0;
for (int i = 0; i < MAX_ITERATIONS; i++) {
long double a1 = a * a - b * b;
long double b1 = 2 * a * b;
a = a1 + ai;
b = b1 + bi;
if ((a + b) > 2) {
break;
}
n++;
}
int bright = map(n, 0, MAX_ITERATIONS, 0, 255);
if ((n == MAX_ITERATIONS) || (bright < 20)) {
bright = 0;
}
int red = map(bright * bright, 0, 65025, 0, 255);
int green = bright;
int blue = map(sqrt(bright), 0, sqrt(255), 0, 255);
Uint32 color = SDL_MapRGB(screen->format, red, green, blue);
Uint32* pixels = (Uint32*)screen->pixels;
pixels[(y * screen->pitch / 4) + x] = color;
}
}
SDL_Flip(screen);
count++;
}
SDL_Quit();
return 0;
}
' function with arguments
var g : g = 50 : wcolor 0,0,0 : mode 1
fcolor 150,240,150 :print 5,10,"global:": print 100,10,g : swap
' func call with params...
myFn(5,3+g,2*sin(90))
func myFn(var a,var b,var c)
fcolor 250,200,150
print 50,30,"local a"
print 50,50,a
print 50,80,"local b"
print 50,100,b
var f : f = a + b + c
fcolor 150,200,250 :print 5,150,"result:": print 100,150,f
swap
endFn