Exemple #1
0
static throw_score_err_s
next_throw_score(const game_state_s *const gs, char throw_char)
{
    assert(gs);

    throw_score_err_s ret = {0};

    if (is_digit(throw_char)) {
        ret.value = throw_char - '0';
        if (is_second_in_frame(gs)) {
            if (ret.value + prev_throw_score(gs) > TOTAL_PINS) {
                ret.error = err_more_than_ten_pins;
                goto fail;
            }
        }
    } else if (is_spare(throw_char)) {
        if (!is_second_in_frame(gs)) {
            ret.error = err_spare_on_second_only;
            goto fail;
        }
        ret.value = TOTAL_PINS - prev_throw_score(gs);
    } else if (is_strike(throw_char)) {
        if (is_second_in_frame(gs)) {
            ret.error = err_stike_on_first_only;
            goto fail;
        }
        ret.value = TOTAL_PINS;
    }

fail:
    return ret;
}
Exemple #2
0
/*
 * Bring the specified vdev online
 */
int
zpool_vdev_online(zpool_handle_t *zhp, const char *path)
{
	zfs_cmd_t zc = { 0 };
	char msg[1024];
	nvlist_t *tgt;
	boolean_t avail_spare;
	libzfs_handle_t *hdl = zhp->zpool_hdl;

	(void) snprintf(msg, sizeof (msg),
	    dgettext(TEXT_DOMAIN, "cannot online %s"), path);

	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == NULL)
		return (zfs_error(hdl, EZFS_NODEVICE, msg));

	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);

	if (avail_spare || is_spare(zhp, zc.zc_guid) == B_TRUE)
		return (zfs_error(hdl, EZFS_ISSPARE, msg));

	if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_ONLINE, &zc) == 0)
		return (0);

	return (zpool_standard_error(hdl, errno, msg));
}
Exemple #3
0
static throw_char_err_s
next_throw_char(const game_state_s *const gs,
                char throw_char,
                uint8_t throw_score)
{
    assert(gs);

    throw_char_err_s ret = {0};

    if (is_zero(throw_char)) {
        ret.value = '-';
    } else if (is_digit(throw_char)) {
        ret.value = throw_char;
        if (is_second_in_frame(gs)
            && throw_score + prev_throw_score(gs) == TOTAL_PINS) {
            ret.value = '/';
        }
    } else if (is_spare(throw_char)) {
        ret.value = '/';
    } else if (is_strike(throw_char)) {
        ret.value = 'X';
    } else if (is_fault(throw_char)) {
        ret.value = 'F';
    }

fail:
    return ret;
}
Exemple #4
0
	int BowlingGame::score_frame(int num) const {
		if (is_strike(num)) {
			return score_strike(num);
		} else if (is_spare(num)) {
			return score_spare(num);
		} else {
			return score_normal(num);
		}
	}
Exemple #5
0
int bowling_game_score(struct bowling_game *game)
{
	int score = 0;
	int frame_index = 0;
	for (int frame = 0; frame < 10; ++frame) {
		if (is_strike(game, frame_index)) {
			score += strike_score(game, frame_index);
			frame_index += 1;
		} else if (is_spare(game, frame_index)) {
			score += spare_score(game, frame_index);
			frame_index += 2;
		} else {
			score += normal_score(game, frame_index);
			frame_index += 2;
		}
	}
	return score;
}
Exemple #6
0
int get_score(void) {
    int score = 0;
    int frame_index = 0;

    for (int frame = 0; frame < 10; frame++) {
        if (is_strike(frame_index)) {
            score += get_strike_score(frame_index);
			frame_index++;
        } else if (is_spare(frame_index)) {
            score += get_spare_score(frame_index);
            frame_index += 2;
        } else {
            score += get_default_score(frame_index);
            frame_index += 2;
        }
    }
    return score;
}
Exemple #7
0
int bowling_game_score() {
  int score = 0;
  int frame_index = 0;
  for(int frame=0; frame < max_frames; frame++) {
    if( is_strike(frame_index) ) {
      score += strike_score(frame_index);
      frame_index++;
    }
    else if( is_spare(frame_index) ) {
      score += spare_score(frame_index);
      frame_index += 2;
    }
    else {
      score += frame_score(frame_index);
      frame_index += 2;
    }
  }
  return score;
}
Exemple #8
0
/*
 * Take the specified vdev offline
 */
int
zpool_vdev_offline(zpool_handle_t *zhp, const char *path, int istmp)
{
	zfs_cmd_t zc = { 0 };
	char msg[1024];
	nvlist_t *tgt;
	boolean_t avail_spare;
	libzfs_handle_t *hdl = zhp->zpool_hdl;

	(void) snprintf(msg, sizeof (msg),
	    dgettext(TEXT_DOMAIN, "cannot offline %s"), path);

	(void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name));
	if ((tgt = zpool_find_vdev(zhp, path, &avail_spare)) == NULL)
		return (zfs_error(hdl, EZFS_NODEVICE, msg));

	verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &zc.zc_guid) == 0);

	if (avail_spare || is_spare(zhp, zc.zc_guid) == B_TRUE)
		return (zfs_error(hdl, EZFS_ISSPARE, msg));

	zc.zc_cookie = istmp;

	if (ioctl(zhp->zpool_hdl->libzfs_fd, ZFS_IOC_VDEV_OFFLINE, &zc) == 0)
		return (0);

	switch (errno) {
	case EBUSY:

		/*
		 * There are no other replicas of this device.
		 */
		return (zfs_error(hdl, EZFS_NOREPLICAS, msg));

	default:
		return (zpool_standard_error(hdl, errno, msg));
	}
}