Author: Uri Blass
Date: 14:00:21 08/29/04
Go up one level in this thread
On August 29, 2004 at 15:39:48, Bas Hamstra wrote: >On August 29, 2004 at 12:04:47, Uri Blass wrote: > >>I have the following code similiar to tscp (tscp is using the variable line >>instead of buffer. >> >>if (!fgets(buffer, 256, stdin)) >> return; >> >>I have the following questions: >>1)How is it possible to have >>!fgets(buffer, 256, stdin) >> >>I understand that it happens only in case of an error but >>I do not see how there can be an error. > >Here is the Borland documentation: > >Syntax > >#include <stdio.h> >char *fgets(char *s, int n, FILE *stream); >wchar_t *fgetws(wchar_t *s, int n, FILE *stream); // Unicode version > >Description > >Gets a string from a stream. > >fgets reads characters from stream into the string s. The function stops reading >when it reads either n - 1 characters or a newline character whichever comes >first. fgets retains the newline character at the end of s. A null byte is >appended to s to mark the end of the string. > >Return Value > >On success fgets returns the string pointed to by s; it returns NULL on >end-of-file or error. > >>2)Is it safe to use fgets()? >>I remember that it is not safe to use gets() and I think that for the same >>reason it is not safe to use fgets() > >As long as you buffer is large enough it it safe. It just takes a line from >stdin and puts it in a string variable. > >>3)I plan to replace this code by a waiting function. >>The point is that I need to wait passively to commands in different places >>one case is when I do not ponder and it is the opponent move but even when I >>ponder during the search I may want to wait(for example if I finished the >>maximal depth). >> >>Today movei has no waiting function and in case of finishing to search during >>pondering it simply unmake the pondered move and go to the main loop. >> >>I think that it is better not to finish the search in case of pondering and >>simply call wait during the search to wait passively to winboard command when >>wait may call a function that read wb input during searching(can be ponder mode >>play mode or analysis mode). >> >>Do you have a waiting function in your code? >> >>Uri > >You can chose 2 approaches: > >a) use a thread to check for i/0 >b) use a search-interrupt > >I think your waiting functions refers to a)? No Personally I use b) because it's >more portable. a) is easier once you have figured out threads. > >Bas. I use a search interrupt. I have no experience with threads. When I search I look for winboard command every 8192 nodes. When I do not search I wait passively for winboard commands. I simply have 2 cases when I should wait passively for winboard commands and this is the reason that I thought to use a function. Case 1 is when I am not during search and case 2 is when I am pondering and do nothing(because I finished to search because of maximaldepth or mate or book move. Today I undo the move in case 2 and go to wait passively for winboard command like I do in case 1. I think that a better solution is not to undo the move and wait passively for winboard command and undo the move only in case that I was wrong in predicting the move but if I do it I need some waiting function that I call from the search. having a waiting function seems to me more elegant solution then the solution that I use today but I am not sure what I should do in case that fgets returns 0 and if it is a possibility that I should care about. Note that for a program that remember results of previous search it is not important if it undo move only to make it again but I think that waiting function is still more elegant than undo move only to make it later. Movei of today does not remember results of previous search so in case that I find a mate after the expected move and undo the expected move,Movei needs to find the mate again. I may change it later but I prefer to keep it that way in the near future. Uri
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.