X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fhanoi.c;h=034878abb526fa6668646366de4b5b43af730a6b;hb=205ea499dbbceba5201d997fbd8b6b1f7f29bd50;hp=f24ae54fa8e753cffbb978254061bae048f67af2;hpb=5d8dbcdd9423bf9821db414fd9ec792ccf1f1027;p=ncurses.git diff --git a/test/hanoi.c b/test/hanoi.c index f24ae54f..034878ab 100644 --- a/test/hanoi.c +++ b/test/hanoi.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2014,2017 Free Software Foundation, Inc. * + * Copyright 2019-2021,2022 Thomas E. Dickey * + * Copyright 1998-2014,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +42,7 @@ * * Date: 05.Nov.90 * - * $Id: hanoi.c,v 1.39 2017/09/09 00:19:24 tom Exp $ + * $Id: hanoi.c,v 1.44 2022/07/28 00:31:22 tom Exp $ */ #include @@ -124,6 +125,15 @@ InitTiles(void) Pegs[2].Count = 0; } +static int +two2n(int n) +{ + int result = 1; + while (n-- > 0) + result *= 2; + return result; +} + static void DisplayTiles(void) { @@ -133,7 +143,7 @@ DisplayTiles(void) erase(); MvAddStr(1, 24, "T O W E R S O F H A N O I"); MvAddStr(3, 34, "SJR 1990"); - MvPrintw(19, 5, "Moves : %d of %.0f", NMoves, pow(2.0, (float) NTiles) - 1); + MvPrintw(19, 5, "Moves : %d of %d", NMoves, two2n(NTiles) - 1); (void) attrset(A_REVERSE); MvAddStr(BASELINE, 8, " "); @@ -282,7 +292,7 @@ main(int argc, char **argv) } setlocale(LC_ALL, ""); - switch (ch = (argc - optind)) { + switch (argc - optind) { case 2: if (strcmp(argv[optind + 1], "a")) { usage(); @@ -354,6 +364,6 @@ main(int argc, char **argv) } } } - exit_curses(); + stop_curses(); ExitProgram(EXIT_SUCCESS); }