• Aucun résultat trouvé

Competitive Analysis of the Windfall Game

Dans le document 123 Fun withAlgorithms (Page 194-197)

Rudolf Fleischer1and Tao Zhang2

1 School of Computer Science, IIPL, Fudan University, Shanghai, China and GUtech, CS Department, Muscat, Oman

2 PICB, Shanghai, China {rudolf,taozhang}@fudan.edu.cn

Abstract. We study the classical computer game ”Super Mario Power Coins” as an online maximization problem with look-ahead. We show nearly matching lower and upper bounds for deterministic online algorithms.

1 Introduction

Super Mario Power Coins is a classical computer game [4]. While coins (and other stuff) are falling from the sky (the top of the screen), Mario must run around on the ground (the bottom of the screen) and try to catch as many coins as possible (while dodging all the other stuff). Since the coins are falling at the same speed as Mario is running, usually he cannot catch all the coins but must choose a path that allows him to catch as many coins as possible. Fig. 1 shows a screenshot of the game.

As we will see in the next section, this game may be modeled similar to a benefit task system. However, we can improve on the general bounds for benefit task systems exploiting some structural properties particular toWindfall.

2 Definitions

Formally, we can model this game as an online problem with look-ahead, which we callWindfall. We assume that coins have diameter one and they can only fall down at integer coordinates. Mario can also only live at integer coordinates, and he can only catch a coin when he is at the same place as the coin.

We denote the width of the screen by d, where the width does not include the two boundary columns 0 (leftmost column) andd+ 1 (rightmost column), which may also have coins falling down. This is motivated by our results because, basically, Mario can usually make an optimal move when he is in a boundary column (either stay, or move inwards), so the performance only depends on the

RF acknowledges support by the National Natural Science Foundation of China (No. 60973026), the Shanghai Leading Academic Discipline Project (project number B114), the Shanghai Committee of Science and Technology of China (09DZ2272800), the Robert Bosch Foundation (Science Bridge China 32.5.8003.0040.0), and the Re-search Council (TRC) of the Sultanate of Oman.

A. Ferro, F. Luccio, and P. Widmayer (Eds.): FUN 2014, LNCS 8496, pp. 183–193, 2014.

c Springer International Publishing Switzerland 2014

184 R. Fleischer and T. Zhang

Fig. 1.Mario tries to catch many coins. In this instance, there exists a path where he can catch one coin in every step. We haved= 5 andn=L= 9, and thusD= 2 and K= 7;σis the corresponding input matrix.

interior widthd. LetL≥1 be the height of the visible screen.Landdare fixed throughout this paper. We defineD=d2andK=L−D, and we assume that K≥1 (this will be justified later).

The input to Windfall is a sequence σ = σ1σ2· · ·σn of (d+ 2)-ary 0/1 vectors, whereσtprovides the positions of coins that appear in steptat the top levelL (the top row of the screen). We can view σas an (n×(d+ 2))-matrix with 0/1 entries, whereσ1 is the bottom row andσn the top row. Note thatn, the length of the input sequence, is not known a priori; only at timen−L+ 1 Mario will realize that the game will end after the nextL−1 steps.

Instead of coins falling down on the screen, we can instead assume that the coins are at fixed positions in the matrixσ and Mario is moving one row up in every step. He can in each step choose whether to stay in his current column, or move one cell to the left or one cell to the right. If he moves to a cell containing a coin, hecatches it (in the original game, this means that, in every step, Mario moves to his new position at a constant speed of 1, while at the same time the coins are falling down at the same speed; Mario can only catch a coin at the end of his move, i.e., we may think of the coins first falling down one level and then Mario moving to his new position where he may catch a coin). Formally, Mario’s goal is to find a feasible path P = (p1, . . . , pn) through the matrix, where the pi are cell coordinates, so as to maximize his profitn

t=1σt(pt).P isfeasible if thex-coordinate changes by at most one frompitopi+1, while they-coordinate increases by exactly one, for alli.

In the offline Windfall problem, Mario knows σ. Computing an optimal path is easy in this case, it is equivalent to finding a shortest path in the directed graph where each cell has three edges to its three adjacent cells in the row above, and the edge to vertex (t, j) has cost 1−σt[j].

Competitive Analysis of the Windfall Game 185 In the online problem with look-ahead L, Mario can only see rowst to t+L when standing in rowt(he could also remember earlier rows, but this does not help him; even knowledge of rowtis useless for planning the next move). When we say at time t, we always mean the positions of Mario and the coins after Mario moved to rowt, i.e., Mario is standing at a cell in rowtcontemplating his move to rowt+ 1. He must decide this move without knowing the rows above t+L. At timet= 0, rowsσ1toσLare revealed, and Mario can choose his initial positionp1 in row 1 arbitrarily. For an online algorithm A, we denote its profit onσbyCA(σ), while we useCopt(σ) to denote the optimal offline profit. We say Aisc-competitive ifCopt≤c·CAfor allσ.

2.1 Benefit Task Systems

Jayram et al. [2] introducedbenefit task systems to study the online load alloca-tion problem in a server farm. Benefit task systems can also model maximizaalloca-tion variants ofk-server problems [3] and metrical task systems [1]. In a benefit task system, we can be in any one of a finite number of states, but the benefit of changing states is time dependent.

To be more precise, for each time t = 0, . . . , n let Ut be the set of possible states, and letBt: (Ut×Ut+1) IR+ be the benefit function, measuring the benefit of changing to a state inUt+1 in stept. Starting froms0, a server must choose a state st+1 in each time step t, gaining benefit Bt(st, st+1), so as to maximize the total benefitt1

n=0Bt(st, st+1). In the online problem with look-aheadL, the server only knowsBt, . . . , Bt+L1 at timet.

Jayram et al. proposed a (1 + L1)-competitive randomized online algorithm for benefit task systems, which matches a lower bound of 1 + L1 for the competitive ratio of any randomized online algorithm. In the deterministic case, there is still a gap between the lower bound of 1+L1+L21+1and an upper bound of min{1+L47,(1+L1)·√L

L+ 1}, which is asymptotically equal to 1+Θ(logLL). They also considered the special case of look-aheadL= 1 and showed a deterministic lower bound of 4 versus an upper bound of 4.

2.2 Our Results

Windfallcould nearly be viewed as a benefit task system, where the sets Ut

are the sets of positionsptfor Mario, andBt(pt, pt+1) =σt(pt+1) if|pt−pt+1| ≤ 1, and Bt(pt, pt+1) = −∞ otherwise (which effectively prevents Mario from jumping to non-neighboring cells). The negative benefit for the illegal jumps makes it impossible to apply the results of Jayram et al. toWindfall, but we acknowledge that our algorithms were inspired by their work.

In this paper we show that we can obtain stronger bounds forWindfallthan the bounds for general task systems. In Section 3, we show that no deterministic online algorithm can be better thanL+Ld/2d/2-competitive. In Section 4, we present several online algorithms for Windfall. We propose a (d+ 1)-competitive al-gorithm,Greedy, which is optimal ifK= 1. For the cased= 1, the algorithm

186 R. Fleischer and T. Zhang

Perfectis optimally L+1L -competitive. For largerd,Perfectgeneralizes to a simple (1 +2dK2)-competitive algorithm,NaturalBreak. A refinement of this algorithm yields the (1 + K/d

d)-competitive algorithmCleverBreak. All four algorithms work in phases, and in each phase Mario tries to catch coins optimally (or, at least, c-competitively). He may also need a few steps between phases, willfully missing coins, to adjust the starting position for the next phase. Jayram et al. [2] used similar ideas for their online algorithms for benefit systems.

Dans le document 123 Fun withAlgorithms (Page 194-197)